The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)

20140103

[SOLVED] JBoss EAP6, JSF, Primefaces: "Unable to find matching navigation case with from-view-id..."

our company app is configured so that when a user clicks the login button from the front page, and index.html file redirects the user to the main page of the authenticated/authorized area of our app, index.xhmtl (rendered as index.jsf), but since the user hasn't logged in yet, they are shown the login page: login.xhml (rendered as login.jsf), BUT in the browser URI field it shows:
examples.com/index.jsf






my problem was trying to get a navigation rule working, so that if during the authentication/login process, if the app found out that the user needed to change his password, he would be redirected to /newPassword.xhtml

but it wasn't working and i was getting this error:
"Unable to find matching navigation case with from-view-id login.xhtml..."

i found out eventually that the from-view-id needed to be the page that was shown in the browser URI field, namely index.xhtml, and not login.xhtml.


here are the relevant code and configurations.

#############
/login.xhtml
#############

<p:commandButton value="Login" update="checkPassword" action="#{loginBean.login}" ... />


#############
LoginBean.java
#############




...
private String changePass = "newPassword";
...
public String login() {
    ...

    if(mustChangePassword) {
        ...
        return changePass;
    }
}

...


#############
WEB-INF/faces-config.xml
#############

<faces-config ... >

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

        <navigation-case>
            <from-action>#{loginBean.login()}</from-action>
            <from-outcome>newPassword</from-outcome>
            <to-view-id>/newPassword.xhtml</to-view-id>
            <redirect />
        </navigation-case>
        ...
    </navigation-rule>

</faces-config>





No comments:

Post a Comment