• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

JSF Page Navigation on SelectOneMenu change

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a selectonemenu in my jsf page and i need to navigate to different pages based on the value selected in the selectonemenu.

I tried two approaches:

1. First approach is to have a hidden button and then invoking the action of the button when the selectonemenu is clicked. This gives me 'hX_5 is undefined' javascript error, even though the hxclient_v3_0.js is included in the page. Below is the code snippet for the same.

<h:selectOneMenu id="menCategory" styleClass="selectOneMenu" value="#{pc_AdvancedDeal.menuCategory}">
<h:selectItem....

<hx:behavior event="onchange" target="menCategory" behaviorAction="click" targetAction="buttonNav"></hx:behavior>

</h:selectOneMenu>

<hx:commandExButton style="display:none" type="submit" value="Submit" id="buttonNav" styleClass="commandExButton" action="#{pc_AdvancedDeal.doButtonNavAction}"></hx:commandExButton>


2. Second approach is to navigate to the required page using response.sendRedirect in the valueChangeListener for the selectonemenu.
With this approach, the control comes back to the initial page and no navigation happens.


Please help. This is very urgent.

Thanks and Regards,
Anitha.
 
Saloon Keeper
Posts: 28416
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the first thing to keep in mind is that the generated HTML control for a dropdown control changes only to the user's browser data, and does not send messages to the server when the control changes. I think you know that, but it's worth mentioning, since a lot of sites make this a more friendly option by having a javascript onChange function do a submit when the menu selection changes. Which makes the droplist look more interactive than it is.

Having said that, I move on to the actual submit button: your commandButton control. The way that command actions work in JSF is that their associated methods get called, and those methods return a String result. This result is looked up in the map defined in your JSF config XML file to determine where to go.

So, at its simplest, all you have to do is let the menu setter method store a command value, then return that command value on your command acttion, and map the command values to navigation specs in jsf-config.xml!
reply
    Bookmark Topic Watch Topic
  • New Topic