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>
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
actionListenerattribute should not be used there (only ActionListener type methods are allowed there). Use that method instead in theactionattribute of the command button.A method that correctly implements the
ActionListenerinterface has a return type ofvoidand as a result will not implicitly do any JSF-based navigation. A regular method expression returning a type ofStringhowever is what is used for JSF based nav.