Unable to find matching navigation case with from-view-id '/login.xhtml' for action '#{admin.Validity}' with outcome 'failure'

jsf

Solution

Your managed bean is named `#{admin}`,

@ManagedBean(name="admin")

however you attempted to access it as `#{Admin}` in the navigation case,

<from-action>#{Admin.Validity}</from-action>

so it definitely won't work. Java is case sensitive.

Fix the managed bean name in the navigation case accordingly:

<from-action>#{admin.Validity}</from-action>

Unrelated to the concrete problem, you've several minor design mistakes.

Managed bean name already defaults to the classname with 1st character lowercased. So your `@ManagedBean(name="admin")` can just be replaced by `@ManagedBean`.

@ManagedBean
@SessionScoped
public class Admin implements Serializable {

Method names should not start with uppercase. Replace `Validity()` by `validity()`. Further there's also a grammatical/language mistake in the method name, but that's probably the language barrier. You'd normally have named it `validate()` or in this context better `authenticate()` or something.

Navigation cases are soo JSF 1.x. Since JSF 2.0 you can utilize the new "implicit navigation" feature. You can use the outcome value as mapping/extension-less view ID.

public String authenticate() {
    if (username.equals("admin") && password.equals("admin")) {
        authenticated=true;
        return "main";
    } else {
        authenticated=false;
        return "login";
    }
}

This way you can remove the whole `<navigation-rule>` block altogether.

See also:

- Communication in JSF 2.0

Problem

I can't get it to work. i get the following: ``` Unable to find matching navigation case with from-view-id '/login.xhtml' for action '#{admin.Validity}' with outcome 'failure' ``` this is the code i'm using: HTML: ``` <div id="main" > <h:form id="login_form"> <table> <tr> <td><h:outputText value="User: " /></td> <td><h:inputText id="username" value="#{admin.username}" /></td> </tr> <tr> <td><h:outputText value="Password: " /></td> <td><h:inputSecret id="password" value="#{admin.password}" /></td> </tr> <tr> <td></td> <td><h:commandButton value="Login" type="submit" action="#{admin.Validity}" /></td> </tr> </table> </h:form> </div> ``` Admin.java ``` import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="admin") @SessionScoped public class Admin implements Serializable { /** * */ private static final long serialVersionUID = 1L; Boolean authenticated; String username; String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String Validity() { if(username.equals("admin") && password.equals("admin")) { authenticated=true; return "success"; } else { authenticated=false; return "failure"; } } } ``` faces-config.xml ``` <faces-config xmlns="http://java.sun.com/xml/ns/javaee" 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_2_0.xsd" version="2.0"> <navigation-rule> <from-view-id>/login.xhtml</from-view-id> <navigation-case> <from-action>#{Admin.Validity}</from-action> <from-outcome>success</from-outcome> <to-view-id>/main.xhtml</to-view-id> <redirect/> </navigation-case> <navigation-case> <from-action>#{Admin.Validity}</from-action> <from-outcome>failure</from-outcome> <to-view-id>/login.xhtml</to-view-id> </navigation-case> </navigation-rule> </faces-config> ``` thank you. Y

Original source