We are migrating from Jsf 1.2 to 2.0 and having validation issues with drop down values updated through ajax using servlets.
What happens today is when a drop-down A is changed dropw-down B's values are fetched through ajax call using a servlet and in Jquery the drop-down values of B is changed based on the Ajax result but after migrating to JSF 2.0 we are getting invalid values issue for drop-down B when submitting the form because the updated drop-down values are not known to faces so wondering why it worked in JSF 1.1 but not 2.0. The bean is requestscoped
I know there is f:ajax with 2.0 but due to time constraint we are going to keep the servlets to make the ajax call if possible.
JSP
<t:datalist value ='#{bean.locations}' var='loc'>
<h:selectOneMenu id="country" value="#{loc.country}" onchange ='getStateListThroughServletAjax(this)'>
<f:selectItems value ='#{loc.countryList}'/>
</h:selectOneMenu>
<h:selectOneMenu id='states' value ='#{loc.state}'>
<f:selectItems value='#{loc.stateList}'/>
</h:selectOneMenu>
</t:datalist>
Javascript
function getStateListThroughServletAjax(country){
//this get the Statelist based on country selected by hitting the servlet
var params = 'countryId='+ country.value;
$.ajax({type: "POST", url: '\loadStates',data: params,
success: function(response) {
jsonResult = jQuery.parseJSON(response);
//setComboOptions for state dropwdown based on JsonResult
setComboOptionsForState(jsonResult)
}
});
}
Anytime i change the country i get a new statelist populated but while saving i get "Validation Error: Value is not valid ".
Any input is appreciated