简体   繁体   中英

How do I specify Navigation Rules if I do not want to make entries in faces-config.xml

Right now I am giving my navigation rules in the faces-config.xml file. If I want to stop making entries in faces-config.xml.

How can i specify the navigation rules if I don't want to do it in faces-config.xml?

"faces-config.xml"

<?xml version="1.0"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xi="http://www.w3.org/2001/XInclude" 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_1_2.xsd">
    <navigation-rule>
        <description>Navigation from the hello page.</description>
        <from-view-id>/login.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/wsListing.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>
    <navigation-rule>
        <description>Navigation from the hello page.</description>
        <from-view-id>/wsListing.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>ebzService</from-outcome>
            <to-view-id>/ebzinput.xhtml</to-view-id>
            <redirect />
        </navigation-case>
        <navigation-case>
            <from-outcome>filterEbz</from-outcome>
            <to-view-id>/filterebzinput.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>


    <navigation-rule>
        <description>Navigation from the hello page.</description>
        <from-view-id>/ebzinput.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>success</from-outcome>
            <to-view-id>/ebzoutput.xhtml</to-view-id>
            <redirect />
        </navigation-case>
        </navigation-rule>

</faces-config>

Implicit navigation is only supported since JSF 2.0. As per the XML file root declaration and your question history, you're using JSF 1.2, so that's end of story.

However, based on your current navigation cases, you seem to be redirecting everytime. For that you could also use ExternalContext#redirect() instead.

public void login() throws IOException {
    // ...

    FacesContext.getCurrentInstance().getExternalContext().redirect("wsListing.xhtml");
}

Or, if you actually don't need to perform business actions at all, just use a normal link.

<h:outputLink value="ebzinput.xhtml">go to ebzinput</h:outputLink>

The additional advantage is that it becomes searchbot-indexable (and thus better SEO).

Instead of "success" the action method may return a view id, for example

public String login() { return "wsListing"; }

This way you can shift your navigation rules to your managed beans. If you want to enforce a redirect use

public String login() { return "wsListing?faces-redirect=true"; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM