動作させることができません。私は次のようになります:
Unable to find matching navigation case with from-view-id '/login.xhtml' for action '#{admin.Validity}' with outcome 'failure'
これは私が使用しているコードです:
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>
ありがとうございました。Y