Reputation: 1778
When I click the search button, I'm trying to have my index.xhtml take me to another page w/ the results. I'm using primefaces JSF.
My problem is that I can't get it to go to the next page. It is calling my searchController beans findItem method, but the resulting pages doesn't change. It just stays on the index.xhtml page.
Anyone have ideas?
@ManagedBean(name="sController")
@RequestScoped
public class SController implements Serializable {
private static final long serialVersionUID = 1L;
public SController() { }
public String findItem() {
System.out.println("findItem called!");
return "success";
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Here's my faces-config.xml.
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-action>#{sController.findItem}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/items.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
And here's my index.xhtml.
<f:view>
<h:form>
<p:panel id="search" header="Search Item">
<p:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Name" for="name"/>
<p:inputText id="name" value="#{sController.name}"/>
</p:panelGrid>
</p:panel>
<p:commandButton value="Search"
actionListener="#{sController.findItem}"/>
</h:form>
</f:view>
Upvotes: 0
Views: 1265
Reputation: 7133
replace the actionListener with action:
<p:commandButton value="Search" action="#{sController.findItem}"/>
append faces-redirect=true
to your returned string to get redirected to the success page:
public String findItem() {
System.out.println("findItem called!");
return "success?faces-redirect=true";
}
Upvotes: 2
Reputation: 20691
That's a workaround. For the benefit of anyone else who might visit this page with the same problem, your page failed to navigate because the method expression you're using in the actionListener
attribute should not be used there (only ActionListener type methods are allowed there). Use that method instead in the action
attribute of the command button.
A method that correctly implements the ActionListener
interface has a return type of void
and as a result will not implicitly do any JSF-based navigation. A regular method expression returning a type of String
however is what is used for JSF based nav.
Upvotes: 3