I have a selectonemenu where a change in the selection should navigate the user to the related page.
So, how do I simulate the action handling of a commandbutton using a selectonemenu control (or are there a more elegant ways to achieve this)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t go around a shot of Javascript for this. Basically you need to let the Javascript submit the request to the server side. In a HTML
<select>element (which is been generated by the JSFh:selectOneMenu) you can best use theonchangeattribute for this. Any JS which you attach to this event will be invoked whenever the user changes the value of the element.or if you’re lazy in writing, this shorthand is also correct:
This will submit the form in combination with the firstnext HTML
input type="submit"element inside the same form (which is been generated by the JSFh:commandButton).You need to write logic in the action method which causes the navigation action as definied in
faces-config.xmlto be taken place. Example:If you do not want to use an
commandButton, then you can also go ahead with abusing thevalueChangeListener:In the bean you then have:
Alternatively, if you already have the desired URL’s as
f:selectItemvalues, then you can also go ahead with just only JS and no bean actions: