a4j:commandButton doesn't submit form field whereas a4j:supp
tazman Mar 14, 2007 4:53 AMHi all!
I'm having a difficult time with a form for user registration. I'm using a4j 1.0.7 with Seam 1.2 on top of JBoss 4.0.5.
The form looks like this:
<h:form id="register_form"> <!-- OTHER FORM FIELDS LIKE name, username, etc.--> <a:region id="locationRegion" selfRendered="false" renderRegionOnly="false"> <!-- country --> <h:outputLabel for="country">country</h:outputLabel> <h:selectOneMenu id="country" value="#{location.country}" required="false"> <f:selectItems value="#{location.countries}"/> <a:support event="onchange" reRender="statePanel, cityPanel" limitToList="true" ajaxSingle="true"/> </h:selectOneMenu> <!-- state --> <h:outputLabel for="state">state</h:outputLabel> <a:outputPanel id="statePanel"> <h:selectOneMenu id="state" value="#{location.state}" required="false"> <f:selectItems value="#{location.states}"/> <a:support event="onchange" reRender="cityPanel" limitToList="true"/> </h:selectOneMenu> </a:outputPanel> <!-- city --> <h:outputLabel for="city">city</h:outputLabel> <a:outputPanel id="cityPanel"> <h:selectOneMenu id="city" value="#{location.city}" required="false"> <f:selectItems value="#{location.cities}"/> </h:selectOneMenu> </a:outputPanel> </a:region> <a:commandButton reRender="register_form" value="submit" action="#{userManager.persist}"/> </h:form>
location.countries generates a static list of countries. location.states and location.cities loads the list from DB depending on the selected country and state.
// SOME DETAILS ARE OMITTED public class Location { private String country; private String state; private String city; public Map<String, String> getCountries() { // returns a static Map for use in select options } public Map<String, String> getStates() { //loads the list of states from DB } public Map<String, String> getCities() { //loads the list of cities from DB } ... }
Now, when I change the country from the selection list, onchange event is fired, new lists of states and cities are loaded from the database and rerendering occurs correctly. However, if I click on the submit button, the selected values for the country and state are null.
I tried to debug the application. Using a4j log in the browser I can see that in both cases, a:support and a:commandButton, the values are submitted. But in the second case, location.getStates() and location.getCities() get null values for country and state when JSF tries to rebuild the states and cities lists after form submit.
I don't know why this happens. Any ideas?
P.S.: I'm using a region inside the form so that when state changes, country value is also submitted. Otherwise the fields outside of the region get also submitted, which causes validation errors.
tazman