Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JSF with AJAX (XmlHttpRequest)

843844Jan 7 2008 — edited Jan 7 2008
Hi,

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..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 4 2008
Added on Jan 7 2008
6 comments
397 views