【问题标题】:JSF failing to serve a ressource which is already thereJSF 未能提供已经存在的资源
【发布时间】:2015-11-21 05:11:26
【问题描述】:

我有一个 JSF 应用程序,需要登录

<h:commandButton id="btnLoginId" value="Login" action="#{UserLoginMB.login}" styleClass="loginPanelBtn"></h:commandButton>

它可以工作并向 managedBean 感知“正确”的结果,

        public String login() {
            // ...
            return "correct";
        }

之后,返回显示:

Impossible de trouver un cas de navigation 通讯员 depuis l'ID de vue «/home/index.xhtml» pour l'action «#{UserLoginMB.login}» avec le résultat «正确»。

这意味着无法找到与视图 home/index.xhtml 的 ID 相对应的导航方式(Bean.login),结果“正确”

虽然我已将 Faces 配置设置为重定向到 /home/backend/index.xhtml,以防成功(正确返回),

    <!-- navigation-rule for login.xhtml -->
    <navigation-rule>
        <from-view-id>/home/index.xhtml</from-view-id>
        <!-- navigation-case for method login() -->
        <navigation-case>
            <from-action>#{userLoginMB.login}</from-action>
            <from-outcome>correct</from-outcome>
            <to-view-id>/home/backend/index.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

在 apache 日志中:

AVERTISSEMENT: JSF1064 : Impossible de localiser ou de servir une 资源,/home/correct.xhtml.

这意味着无法本地化资源 /home/correct.xhtml 而我从未使用过这样的资源。

【问题讨论】:

    标签: jsf jsf-2 navigation


    【解决方案1】:

    如果 &lt;from-view-id&gt;&lt;from-action&gt; 不完全匹配(它们区分大小写!),则可能会发生这种情况,因此 JSF 无法找到具有所需结果的关联 &lt;navigation-case&gt;。那么 JSF 会默认为隐式导航,也就是说返回的字符串会被当作&lt;to-view-id&gt;

    所以,例如

    public String login() {
        // ...
        return "correct";
    }
    

    并且找不到&lt;navigation-case&gt;,则JSF 将隐式导航到与当前视图位于同一文件夹中的correct.xhtml。这个特性是自 JSF 2.0 以来的新特性,它使开发人员免于编写充满导航案例的所有 XML 样板。在您的特定情况下,您也可以只返回"backend/index",而不是使用导航案例。

    public String login() {
        // ...
        return "backend/index";
    }
    

    另见:

    【讨论】:

    • 我已经明白并更正了,无论如何我会选择这个作为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2022-01-24
    • 2020-12-12
    • 2013-12-15
    • 2011-03-11
    相关资源
    最近更新 更多