JSF How to redirect to another page defined at runtime using Command Button?

I would like to call a Bean method and then redirect the user to a different page which is defined at runtime when that method is called and output by some runtime computation: For example:

on .xhtml:

<p:selectBooleanCheckbox value="#{userAuth.parameterA}"/>
<p:commandButton value="Save Changes" 
                 id="withIcon" 
                 type="submit"
                 actionListener="#{userAuth.saveChanges()}" 
                 icon="ui-icon-disk" />

      

on bean:

public String saveGhanges(){
    this.entity.save(); //dummy code)
    if (this.parameterA == true) return "ATrue.xhtml";
    if (this.parameterA == false) return "AFalse.xhtml";
}

      

+3


source to share


2 answers


try this:

<p:selectBooleanCheckbox value="#{userAuth.parameterA}"/>
<p:commandButton value="Save Changes" 
                 id="withIcon" 
                 type="submit"
                 action="#{userAuth.saveChanges()}" 
                 icon="ui-icon-disk" ajax="false"/>

      



actionListener must be for invalid methods. I hope this helps.

+4


source


Like @pamps, try replacing actionListener

with action

incommandButton

actionListeners

have a return type void

, and actions

can have void

or String

as a return type!



Hope this helps!

+2


source







All Articles