Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF Page Navigation on SelectOneMenu change  RSS feed

Anitha Lingam
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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}">

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


<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,
Tim Holloway
Posts: 18662
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!