0
votes

Is there any way in JSF page navigation to create a joker rule? I have a logout link in my template header (almost for all pages). And I want to give just one rule which navigate all the pages inside the secure folder to the index page in the root.

<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>

I tried this, but the parser said it had not found a rule from /secure/pagex.xhtml to /index.xhtml. Is this true? I have to give a rule for all of my pages one by one?

1

1 Answers

4
votes

The wildcard is only allowed as suffix (as the last character).

<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>

The <from-view-id> is however optional. You could also just remove it.

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

Or, better, use implicit navigation, then you can remove the <navigation-rule> altogether.

E.g. GET

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

Or POST

public String logout() {
    // ...

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

JSF will automatically worry about extension and mapping.

See also: