单击页面上的按钮后,我无法从一个页面导航到另一个页面。我已经定义了导航规则。
<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是
<!-- 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>
答案 0 :(得分:1)
首先,您需要一种方法来在按钮点击后设置操作:
public String nextPage()
{
if (username.equals("guest") && password.equals("guest"))
{
return "loginSuccess";
}
return "loginFailure";
}
接下来您需要做的是将按钮操作属性与方法连接:
<h:commandButton value="Submit Values" action="#{YourBean.nextPage}"/>
然后您需要做的是设置导航规则:
<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>
最后一件事。如果您有这样的映射:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
你应该把所有面孔/ login.xhtml,faces / success.xhtml等等放在一起。