wood burning stoves 2.0*
The moose likes JSF and the fly likes Setting the Action for a CommandButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Setting the Action for a CommandButton" Watch "Setting the Action for a CommandButton" New topic
Author

Setting the Action for a CommandButton

Eric Bresie
Greenhorn

Joined: Apr 05, 2011
Posts: 20
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 ).


Help is appreciated.

Eric
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2242
    
    7

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.

K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Eric Bresie
Greenhorn

Joined: Apr 05, 2011
Posts: 20
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.
Eric Bresie
Greenhorn

Joined: Apr 05, 2011
Posts: 20
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.
 
 
subject: Setting the Action for a CommandButton
 
Similar Threads
illegalArgumentException
JSF keeps displaying old values after Validation Phase fails (ignoring actionListeners settings)
selectOneMenu does not update backing Bean / Application is invoked in phase 2 rather than phase 5
JSF does not call action in managed bean
Ajax listener method is not fire for other(except first) component