RichFaces 3.0.2 dataTable ajaxKeys broken?
ylazzari Jul 25, 2007 5:43 PMHi all,
I have a problem with a dataTable on which I'm trying to partially re-render some rows using the ajaxKeys attribute. I know it's been discussed serveral times on this message board but I just can't seem to make it work. I tried using the a4j:repeat component and it works, but something's wrong when I apply a similar logic inside a dataTable.
Here's my template snippet:
<h:form id="theForm"> <h:outputText value="The list is empty." rendered="#{theList.size == 0}"/> <rich:dataTable id="theTable" value="#{theList}" var="item" rendered="#{theList.size > 0}" ajaxKeys="#{myController.ajaxKeys}"> <a4j:support event="onRowDblClick" action="#{myController.onDoubleClickItem}" reRender="theTable"/> <rich:column> <f:facet name="header">Col 1</f:facet> <h:outputText value="#{item.col1}" rendered="#{not item.editFlag}"/> <h:inputText value="#{item.col1}" rendered="#{item.editFlag}"/> </rich:column> <rich:column> <f:facet name="header">Col 2</f:facet> <h:outputText value="#{item.col2}" rendered="#{not item.editFlag}"/> <h:inputText value="#{item.col2}" rendered="#{item.editFlag}"/> </rich:column> <rich:column> <f:facet name="header"></f:facet> <a4j:commandLink value="Save" action="#{myController.saveSelectedItem}" reRender="theTable"/> </rich:column> </rich:dataTable> </h:form>
Basically, when I double-click on a row, I want that particular row to be re-rendered so that it toggles between being editable or not; inline-editing pattern if you wish.
My template is backed up by a stateful session bean that act as a Seam controller and listens to page events ("myController"). Here's what it looks like (only the important parts were included):
@Stateful @Name("myController") public class MyControllerBean implements MyController { @DataModel private List<Item> theList; @DataModelSelection private Item selectedItem; private Set ajaxKeys; ... public void onDoubleClickItem() { selectedItem.setEditFlag(true); int i = theList.indexOf(selectedItem); Set ajaxKeys = new HashSet(); ajaxKeys.add(i); setAjaxKeys(ajaxKeys); } public void saveSelectedItem() { selectedItem.save(); selectedItem.setEditFlag(false); int i = theList.indexOf(selectedItem); Set ajaxKeys = new HashSet(); ajaxKeys.add(i); setAjaxKeys(ajaxKeys); } public Set getAjaxKeys() { return ajaxKeys; } public void setAjaxKeys(Set ajaxKeys) { this.ajaxKeys = ajaxKeys; } ... }
Now, the problem that I have is that it always re-renders the whole table when I double click on a row or click save on a row that is in edit mode. It doesn't really affect the functionality of the screen but I don't understand why it does so. Actually, I kind of do because I put a breakpoint on my "myController.getAjaxKeys()" method and it never gets called. That can't be good now, can it?! I don't understand why. I tried a similar pattern but using an a4j:repeat tag and it works. The "myController.getAjaxKeys()" method is called and only the "selectedItem" is re-rendered. What this tells me is that the functionality in Ajax4jsf works so it's probably something in RichFaces' dataTable or my way of using it. Can anyone help me? I'm currently using the snapshot of July 25th for both Ajax4jsf and RichFaces but I have the same problem with older snapshots as well.
Thank you very much for any help on the matter.