aspose file tools*
The moose likes JSF and the fly likes JSF Page Navigation on SelectOneMenu change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Page Navigation on SelectOneMenu change" Watch "JSF Page Navigation on SelectOneMenu change" New topic
Author

JSF Page Navigation on SelectOneMenu change

Anitha Lingam
Ranch Hand

Joined: Apr 21, 2002
Posts: 38
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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16142
    
  21

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!


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Page Navigation on SelectOneMenu change