Andrea T
Andrea T

Reputation: 3107

JSF How to redirect to another page determined at runtime with Command Button?

I would like to call a method of a Bean and then, redirect the user to another page that is determined at runtime when this method is called and derived by some runtime calculations: For example:

on the .xhtml:

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

on the bean:

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

Upvotes: 3

Views: 1522

Answers (2)

pamps
pamps

Reputation: 304

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 should be for void methods. i hope it helps.

Upvotes: 4

S1LENT WARRIOR
S1LENT WARRIOR

Reputation: 12204

Just like @pamps said, try replacing actionListener with action in your commandButton

actionListeners have void return type, while actions may have void or String as their return type!

Hope this helps!

Upvotes: 2

Related Questions