I am trying to dynamically set the action of a h:commandButton based on a selected selectOneMenu item (which is populated by database items).
I have a change listener to adjust the managed page beans state to help determine the "next page". The commandButton's action is set on the "next page". My assumption was the value of the "next page" would "dynamically replace" the actual action value, but it keep the original value set initially.
Excerpt of the page:
Excerpt of the bean looks like:
I suspect I need some kind of (i.e. update, render, p:ajax) of some type on the selectOneMenu , but I'm still confused in it's usage and the different ways of dealing with "listeners" (i.e. JSF 1.x listener vs JSF 2.x ajax ).
I don't understand how you going to update the action of the h:commandButton because this action points to a method in the backing bean. What this method does is up to you inside the bean. You mentioned the selected value from the selectOneMenu changes which page to go then as long as the bean knows the selected value, you will be fine.
Under this situation, your selectOneMenu is fine. Everything is done in the backing bean. So when testing once the select menu changes value, display this value to confirm.
The backing bean gets the value from the select One, and updates the "nextPage" propertu, but the resulting rendered HTML still shows the original action not the new bean property value. So if I have items ("one", "two", "three") with a default of "home", and select "one", then backing bean updates the "nextPage" property to be "one", but rendered still shows the equivalent "home" view/page. I tried having a "next()" method (instead of a 'getter/setter" method) as well which uses the nextPage bean property and this didn't work either.
Joined: Apr 05, 2011
After further investigation, it appears my problem was due to a navigation rules I had previously defined in the faces-config.xml when I was working in a JSF 1.x setup but now I am working in JSF 2.x. After removing these, it navigated to the correct view per the properties value.