【发布时间】:2011-03-30 23:36:03
【问题描述】:
我想使用我的 faces-config.xml (JSF 2.0) 的导航规则功能,但我遇到了一些问题。我有三个文件(index.xhtml、index2.html、index3.xhtml),它们看起来像这样:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:loadBundle basename="resources.application" var="bundle"/>
<head>
<title><h:outputText value="#{bundle['welcome.title']}" /></title>
</head>
<body>
<h3>1</h3>
<h:form>
<h:commandButton action="next2" id="nextpagelink" value="Next Link">Next</h:commandButton>
</h:form>
</body>
</html>
(index.xhtml,其他看起来相似,不同的actionnames和其他h3-field)
我的 faces-config.xml 有以下与导航规则相关的条目:
<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">
<application>
<message-bundle>resources.application</message-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
<navigation-rule>
<display-name>index.xhtml</display-name>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>next2</from-outcome>
<to-view-id>/index2.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>index2.xhtml</display-name>
<from-view-id>/index2.xhtml</from-view-id>
<navigation-case>
<from-outcome>next3</from-outcome>
<to-view-id>/index3.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>index3.xhtml</display-name>
<from-view-id>/index3.xhtml</from-view-id>
<navigation-case>
<from-outcome>next1</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>DemoProject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
但是,当我单击 index.xhtml 文件中的链接时,没有任何反应。我没有像我想的那样进入下一页 index2.xhtml
【问题讨论】:
-
有什么理由不使用没有详细 XML 配置文件的隐式导航?顺便说一句:您的问题出在其他地方。到目前为止显示的代码看起来不错。因此,要么您没有显示在您的环境中重现相同问题的最少代码,要么您没有运行您认为正在运行的代码。
-
您的意思是通过 h:outputLink 声明链接?我可以试试这个就代码而言:我在我的真实项目中尝试了导航代码,但它没有工作,所以我在 Eclipse 中使用 JSF 2.0 设置了一个新的动态 Web 项目,复制并重命名了生成的 index.xhtml文件并设置上述导航规则。不多也不少。
-
没有。只是
<h:whatever action="filename">。它将隐式转到filename.xhtml。要获得真正的帮助,您应该提供重现问题的最少代码和环境详细信息。以上没有。它看起来不错,应该可以正常工作。也许你已经从 actual 代码中删除了太多,无法在此处发布。你不应该那样做。您可能在不知不觉中解决了该截止点的问题。 -
我现在已经列出了上面的所有代码。这只是我为测试导航规则而设置的一个真正的小型演示项目。此项目中没有 java-classes,css,..exist
-
对不起,我仍然无法重现这个。我唯一改变的是撕掉那些资源包声明,因为我这里没有这些文件,它们与问题无关。
标签: java jsf navigation jsf-2 faces-config