JSF with AJAX (XmlHttpRequest)
843844Jan 7 2008 — edited Jan 7 2008Hi,
I am trying to implement Ajax response in <h:selectOneMenu> in JSF. To make it clear,
i am having 2 DropDown List.
1) Countries
2) States
First Drop Down List contains countries , if u select a particular country ,the Ajax request should be passed to server and from there u need to get the response back to the client and refresh the second drop down list by including the States for the repective country selected. The reason why i have chosen AJAX here is that only the "States" dropdown list is affected or refreshed for the server response and not the whole JSP page.
I have do this through XmlHttpRequest object itself where i dont have a enough time to think about ajax4jsf and other components. It goes some thing like this:-
Countries:
<h:selectOneMenu id="countries" onchange="ajaxRequest()">
<h:selectitem itemName="Australia" itemValue="Australia"/>
.......
.....
</h:selectOneMenu>
States:
<h:selectOneMenu id="states">
<h:selectitems value="...">
.......
.....
</h:selectOneMenu>
In ajaxRequest javascript function call the xmHttpRequest object,
xmlHttpRequest.open("GET","#{userBean.resultData}", true);
xmlHttpRequest.send();
Here my question is that userBean's resultData is an arraylist which contains the states details for a respective country selected.
But here how this method will be invoked by passing it as a URL to server in xmlHttpRequest.open()? In struts, we can pass it like "sampleAction.do?action=getResultData"+countryId in xmlHttpRequest.open . Where in JSF this
"#{userBean.resultData}" EL language is not accepted? So how can i invoke the method in managed Bean for xmlHttpRequest that has been send? Pls. do provide a solution for this..It is really urgent.
Thanks in advance..