• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic