我可以在 JSF 导航规则中使用通配符 * 吗?

Can I use wildcard character * in JSF navigation rule?

在 JSF 页面导航中有什么方法可以创建小丑规则吗?我的模板 header 中有一个注销 link(几乎所有页面)。我只想给出一个规则,将安全文件夹内的所有页面导航到根目录中的索引页面。

<navigation-rule>
    <from-view-id>/secure/*.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>index</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

我试过了,但是解析器说它没有找到从 /secure/pagex.xhtml/index.xhtml 的规则。这是真的?我必须为我所有的页面一个一个地给出规则吗?

通配符只能作为后缀(作为最后一个字符)。

<navigation-rule>
    <from-view-id>/secure/*</from-view-id>
    <navigation-case>
        <from-outcome>index</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

然而 <from-view-id> 是可选的。您也可以将其删除。

<navigation-rule>
    <navigation-case>
        <from-outcome>index</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

或者,更好的是,使用隐式导航,然后您可以完全删除 <navigation-rule>

例如得到

<h:button ... outcome="/index" />
<h:link ... outcome="/index" />

或POST

public String logout() {
    // ...

    return "/index?faces-redirect=true";
}

JSF 会自动担心扩展和映射。

另请参阅:

  • JSF implicit vs. explicit navigation