I would like when I click on a
<p:commandButton>
,a Bean for processing is called and at the same time, the page should be redirected to another page.
In other words, I would like to combine:
<p:commandButton actionListener="#{processBean.process}" >
</p:commandButton>
And:
<h:link outcome="redirection">
</h:link>
where "redirection" is configured in faces-config.xml
How should I do ? Is there a better way to achieve this ?
Use action
property of p:commandButton.
<p:commandButton actionListener="#{processBean.process}" >
</p:commandButton>
change it to
<p:commandButton actionListener="#{processBean.process}" action="viewIDToRedirect" >
</p:commandButton>
First, actionListener
will be called then navigation will kick in. But remember you'll need to define the Navigation rule in faces-config.xml
Use action
attribute, but don't keep actionListener
anymore.
<p:commandButton action="#{processBean.process}" />
To perform the action without validating the form (eg. DELETE), you could then use process attribute as follows:
<p:commandButton action="#{processBean.process}" process="@this" />
Note returning the target link with faces-redirect=true
public String process() {
...
return "/path/to/some.xhtml?faces-redirect=true";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With