ajax4jsf trouble after a form has failed JSF validation
raindogs Mar 9, 2007 11:07 AMI'm having a problem getting ajax4jsf to play nice with jsf form validation. The page below uses ajax4jsf to run a method from the bean (session scope) when the value in the "state" list changes and update a couple of fields. This works great under most circumstances. However, if the user submits the form *without* filling in the required "addressName" field, the form does not submit and the error message is displayed. This is as it should be. The trouble comes when, if the form has been submitted and is displaying the error message for the "addressName" field, the user changes the "state" field, which should still fire off the "loadState" method. In this case, the "loadState" method never fires and none of the fields in the "reRender" list are refreshed, even if there is now a value in the "addressname" field.
I thought that bypassing validation by adding an immediate="true" to the onload event attached to the "state" field would do the trick. When I put that in the "loadState" method did fire, but none of the fields in the "rerender" list updated. This still seems like it could be the way to go, but I just can't make it work.
The snippet below should show all of the relvant code, any help would be much appreciated.
Thanks,
Alex
<s:subForm id = "locationSubForm"> <h:panelGroup id="locationGroup"> <h:panelGrid columns="2" style="margin-top:10px;" id="locationGrid" border="0" cellpadding="2"> <h:outputText value="Address Name:" /> <h:inputText id="addressName" value="#{locationForm.addressName}" required="true"/> <h:message for="addressName" /> <h:outputText value="" /> <h:outputText value="Street Address:" /> <h:inputText id="streetAddress" value="#{locationForm.streetAddress}" /> <h:outputText value="City:" /> <h:inputText id="city" value="#{locationForm.city}" /> <h:outputText value="State:" /> <h:selectOneMenu value="#{locationForm.state}" style="padding:0px;margin:0px;"> <a4j:support event="onchange" action="#{locationForm.loadState}" reRender="latitude, longitude, city, zipcode" ajaxSingle="true"/> <f:selectItems value ="#{locationForm.stateList}" /> </h:selectOneMenu> ... <t:commandButton action="#{locationForm.submitNewLocation}" value="Submit" actionFor="locationSubForm"/> <h:outputText value=" " escape="false"/> </h:panelGrid> </h:panelGroup> </s:subForm>