Reputation: 1
I am not able to navigate from one page to another after clicking the button on the page. I have defined the navigation rules.
<managed-bean>
<description>helloWorld</description>
<managed-bean-name>helloWorld</managed-bean-name>
<managed-bean-class>com.ritz.web.HelloWorld</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/HelloWorldProg.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
web.xml is
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/HelloWorld.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Upvotes: 0
Views: 2078
Reputation: 2951
First of all you you need a method to set action after button click:
public String nextPage()
{
if (username.equals("guest") && password.equals("guest"))
{
return "loginSuccess";
}
return "loginFailure";
}
Next thing you need to do is connect your button action attribute with method:
<h:commandButton value="Submit Values" action="#{YourBean.nextPage}"/>
Then you need to do is set a navigation rules:
<navigation-rule>
<description></description>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>loginSuccess</from-outcome>
<to-view-id>/loginSuccess.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>loginFailure</from-outcome>
<to-view-id>/loginFailure.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
And one last thing. If you have mapping like this:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
You should put everywehere faces/login.xhtml, faces/success.xhtml and so on.
Upvotes: 1