Sorting a column of comboBoxes in a dataTable causes row dat
douglasi22 Nov 13, 2008 12:54 PMI am having a problem with my data becoming corrupted when I do sorting on a column that is made up of comboBoxes. I have an a4j:support for my comboBox in order to populate another comboBox in the next column. For this particular page I really need to have sorting for the column with the comboBox. When I sort by the column that has the comboBoxes and then save my changes, the changes are made to other rows and not those displayed on the screen. I can also see that my data becomes corrupt within the dataTable. I have created a sample app in order to greatly simplify what is happening.
Here is my JSF code:
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <f:view> <h:form> <rich:dataTable id="dataTable" value="#{testController.infoBeans}" var="infoBean" binding="#{testController.dataTable}" rows="3"> <rich:column id="name" sortBy="#{infoBean.name}"> <f:facet name="header"> <h:outputLabel for="name" value="Name" /> </f:facet> <h:inputText value="#{infoBean.name}"/> </rich:column> <rich:column sortBy="#{infoBean.place}"> <f:facet name="header"> <h:outputLabel for="place" value="Place" /> </f:facet> <rich:comboBox id="place" value="#{infoBean.place}" suggestionValues="#{testController.places}"> <a4j:support event="onselect" /> </rich:comboBox> </rich:column> </rich:dataTable> <br /> <a4j:commandButton value="Reset" reRender="dataTable" action="#{testController.populateInfoBeans}"/> </h:form> </f:view> </jsp:root>
Here is my backing bean:
package test; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.richfaces.component.html.HtmlDataTable; public class TestController implements Serializable { private static final long serialVersionUID = 1L; private List<InfoBean> infoBeans; private List<String> places; private transient HtmlDataTable dataTable; public TestController() { super(); populateInfoBeans(); this.places = new ArrayList<String>(); this.places.add("Alaska"); this.places.add("Colorado"); this.places.add("Delaware"); this.places.add("Florida"); this.places.add("Georgia"); } public void populateInfoBeans() { this.infoBeans = new ArrayList<InfoBean>(); this.infoBeans.add(new InfoBean("Axel", "Alaska")); this.infoBeans.add(new InfoBean("Chad", "Colorado")); this.infoBeans.add(new InfoBean("Doug", "Delaware")); this.infoBeans.add(new InfoBean("Fred", "Florida")); this.infoBeans.add(new InfoBean("George", "Georgia")); } public List<InfoBean> getInfoBeans() { return this.infoBeans; } public void setInfoBeans(List<InfoBean> infoBeans) { this.infoBeans = infoBeans; } public List<String> getPlaces() { return this.places; } public void setPlaces(List<String> places) { this.places = places; } public HtmlDataTable getDataTable() { return this.dataTable; } public void setDataTable(HtmlDataTable dataTable) { this.dataTable = dataTable; } public class InfoBean implements Serializable { private static final long serialVersionUID = 1L; private String name; private String place; public InfoBean(String name, String place) { super(); this.name = name; this.place = place; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String getPlace() { return this.place; } public void setPlace(String place) { this.place = place; } } }
Here is the code in my faces-config.xml to create the managed bean:
<managed-bean> <managed-bean-name>testController</managed-bean-name> <managed-bean-class>test.TestController</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean>
When you run the page, if you sort by name, any changes you make will show up just fine. If you sort by place (column with the comboBoxes) and make some changes, then when you sort again by place you will notice data becomes corrupted. The more you play with it the more it becomes corrupted. I included a reset button to reset all the data back to its original state for convenience in testing.
Some observations I have made is that if I remove the a4j:support, then it all works. If I remove the rows attribute from the dataTable it all works. If I do not sort by places than it all works. The problem is I need all of these things. I'm stumped at how I can leave all these things in and still make it work. Any help would be greatly appreciated.
FYI - I am using Richfaces 3.2.2.