• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

2 Drop Down JSF: AJAX: hx:ajaxRefreshRequest

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic