This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes 2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest" Watch "2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest" New topic
Author

2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest

Vivek Gupta
Greenhorn

Joined: May 02, 2005
Posts: 23
hi,
I have 2 drop downs - one for Country and the other for State. On JSF page load, the Country List is populated. But the State list will be updated only at the selection of the Country. The managed bean has 2 ArrayList, one each for State and Country and also has a Hashmap which has mapping of country with a list of states. The HashMap and the ArrayList of Country has been populated from the WebService call. The arraylist for states is refreshed each time the country is selected.
The arraylist of states is refreshed from the HashMap only.

I implemented this scenario as following-

1.Add the State drop-down to a Panel Group(h:panelGroup). Add the Ajax Support to the Panel and select the Refresh(hx:ajaxRefreshRequest) as the Ajax Request. The request param is passed as the country selected.
2.Specify the behaviour of the country drop-down for onchange event(onActionFunction).
The following was used as a reference to implement this part-
Ajax Supported Java Server Faces Components
3.The Javascript function executed on "onActionFunction" will make Ajax request [Refer to Ajax JSP example] to a Servlet which has a doGet method to update the session with the States ArrayList corresponding to the country selected. This country was passed as input parameter to the Servlet.

This serves my purpose. But I am posting this in order to get any alternative or a better approach to solve the issue - refresh the State list on the selection of country, without any hardcoding(of state and country) on the client side and using only JSF. The whole page should not refresh (even with skipping the validation using immediate as true).

Can anybody suggest if the hx:ajaxRefreshRequest can help me in refresh of the state list without the XMLHttpRequest. Where do I need to add the code for refreshing the state arraylist in session after selecting the list from HashMap<Country:States> if I just use "hx:ajaxRefreshRequest"? The arraylists are directly used in the drop-downs - for example:
......................
......................
<h:selectOneMenu id="country" value="#{MyBean.country}">
<f:selectItems value="#{MyBean.arrlstCountry}"/>
......................
......................

Thanks & Regards
Vivek Gupta
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest
 
Similar Threads
Reset the collection content in bean:define
Strut-Ajax - display states when Country selected
select values for second drop down
changing list values at run-time
javascript help