【问题标题】:navigation rule description not functioning properly in faces-config.xml导航规则描述在 faces-config.xml 中无法正常运行
【发布时间】:2013-09-25 07:08:57
【问题描述】:

点击“GoBack”按钮时 displaypage.xhtml 没有重定向到 frontpage.xhtml 的任何原因?浏览器会从 frontpage.xhtml 重定向到 displaypage.xhtml,但不会反过来。

谢谢

frontpage.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">

<ui:composition template="WEB-INF/templates/origin.xhtml">
    <ui:define name="content">
        <f:view>
            <h:form>
                <h:panelGrid>
                    <h:inputText value="#{user.name}" required = "true"/>
                </h:panelGrid>
                <h:commandButton

                    action="#{user.testcase2()}"
                    value="Search"></h:commandButton>
            </h:form>
            </f:view>


    </ui:define>
</ui:composition>
</html>

displaypage.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">

<ui:composition template="/WEB-INF/templates/origin.xhtml">
    <ui:define name="content">
       <h:panelGrid>
        <h:outputText value="#{user.testclass.inputName}"/>
        <h:commandButton id="back" value="GoBack" action="frontpage"/>
       </h:panelGrid>
    </ui:define>
</ui:composition>
</html>

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>/frontpage.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{user.testcase2()}</from-action>
            <from-outcome>test2</from-outcome>
           <to-view-id>/displaypage.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
         </navigation-rule>
   <navigation-rule>
    <from-view-id>/displaypage.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>frontpage</from-outcome>
                <to-view-id>/frontpage.xhtml</to-view-id>
                <redirect/>
        </navigation-case>
    </navigation-rule>
</faces-config>

【问题讨论】:

    标签: jsf jsf-2 faces-config


    【解决方案1】:

    &lt;h:commandButton&gt; 标记必须被&lt;h:form&gt; 标记覆盖才能激活,尤其是如果&lt;h:commandButton&gt;action 属性包含动态导航(例如:action=#{user.testcase2()})。

    否则,如果最后一个标签只有一个静态导航,(字符串例如:action="frontpage" ),那么就像 M.@BalusC 所说的那样使用&lt;h:button&gt;,因为它不支持动态导航。

    【讨论】:

    • 技术解释表示赞赏。顺便说一句,另一种方法是将其替换为&lt;h:button&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多