Forums Register Login

2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest

+Pie Number of slices to send: Send
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'm doing laundry! Look how clean this tiny ad is:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4986 times.
Similar Threads
Strut-Ajax - display states when Country selected
javascript help
Reset the collection content in bean:define
select values for second drop down
changing list values at run-time
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:05:55.