List not updating in a datatable
waq Apr 13, 2009 10:03 AMI have a datatable in which i have multiple rows. I have two lists and one label. My scenerio is that when one list changes, it updates the second corresponding list of the same row. My code is:
<h:dataTable id="reg_table" value="#{Test.detailList}" var="reg" >
<f:facet name="header">
<h:outputText value="TEST" />
</f:facet>
<h:column >
<f:facet name="header" >
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{reg.name}" />
</h:column>
<h:column >
<f:facet name="header" >
<h:outputText value="Country" />
</f:facet>
<h:selectOneMenu value="#{reg.country}">
<f:selectItems value = "#{reg.country_list}"/>
<a4j:support event="onchange" reRender="city_combo"
action="#{Test.updateList}"/>
</h:selectOneMenu>
</h:column>
<h:column>
<f:facet name="header" >
<h:outputText value="City" />
</f:facet>
<h:selectOneMenu id="city_combo" value="#{reg.city}">
<f:selectItems value = "#{reg.city_list}"/>
</h:selectOneMenu>
</h:column>
</h:dataTable>
public class Bean {
private String name;
private List<SelectItem> country_list = new ArrayList<SelectItem>();
private List<SelectItem> city_list = new ArrayList<SelectItem>();
private String country;
private String city;
..setter and getters
}
public class Test {
private List<Bean> detailList;
public Test() {
this.populate();
}
...setter getter
public void populate() {
List<SelectItem> country_temp = new ArrayList<SelectItem>();
List<SelectItem> city_temp = new ArrayList<SelectItem>();
city_temp.add(new SelectItem("AA"));
country_temp.add(new SelectItem("UK"));
country_temp.add(new SelectItem("Belgium"));
detailList = new ArrayList<Bean>();
detailList.add(new Bean("Abc",country_temp,city_temp, "",""));
detailList.add(new Bean("Xyz",country_temp,city_temp, "", ""));
}//end populate
public void updateList() {
System.out.println("Updating....");
List<SelectItem> city_temp1 = new ArrayList<SelectItem>();
Bean obj;
for(int i=0; i<detailList.size(); i++) {
obj=(Bean) detailList.get(i);
if(obj.getCountry().equals("Belgium")) {
city_temp1.add(new SelectItem("Brussels"));
}
if(obj.getCountry().equals("UK")) {
city_temp1.add(new SelectItem("London"));
}
obj.setCity_list(city_temp1);
}//end for
}//end updateList()
Now when i change the country list i get the exception:
\ javax.servlet.ServletException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(city_combo). Found null. at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178) at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390) at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:595) Caused by: java.lang.IllegalArgumentException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(city_combo). Found null. at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:326) at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:814) at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861) at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286) at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:124)
Where am i doing it wrong? and is my technique ok?