Reputation: 189
I need to navigate from one page to another on button click. It works if I do it like this
<h:commandButton value="Search" action="pageTwo.xhtml" />
but I need to do other things and not just navigate. When I try to use a function
<h:commandButton value="Search" actionListener="#{myLittleBean.doForward}" />
public String doForward() {
// ...
return "pageTwo";
}
it just reloads the pageOne. Where is my mistake?
Upvotes: 0
Views: 192
Reputation: 36
I think This is the problem of your ManagedBean you can also try this one:
**public String doForward() {
// ...
return ("pageTwo.xhtml");
}**
if it does not work then use explicit ManagedBean
Upvotes: -1
Reputation: 1108642
Your mistake is referencing the action method as an action listener instead of a real action. An action listener isn't intented to execute business actions and perform navigation. An action listener is intented to prepare some conditions required for the real action, such as setting a property.
If you just fix the wrong attribute,
<h:commandButton value="Search" action="#{myLittleBean.doForward}" />
then everything should go well.
Upvotes: 3