当前位置: 代码迷 >> J2EE >> jsf 出错 javax.faces.el.MethodNotFoundException
  详细解决方案

jsf 出错 javax.faces.el.MethodNotFoundException

热度:753   发布时间:2016-04-17 23:45:51.0
jsf 报错 javax.faces.el.MethodNotFoundException
用jsf调用方法出现问题,代码如下:
public class Login {
private String username;
private String password;
        //getter() , seter()方法省略
public String check() {
if( "hnisi".equals(password) ) {
return "seccess";
}else {
return "failure";
}
}
}

jsp里的jsf代码:
<f:view>
<h:form>
<h:outputLabel value="name:" />
<h:inputText id="username" value="#{login.username }" required="true">
<f:validateLength maximum="10" minimum="1"></f:validateLength>
</h:inputText>
<h:outputLabel value="pass:" />
<h:inputSecret value="#{login.password }"></h:inputSecret>
<h:commandButton value="Login" action="#{login.check }"></h:commandButton>
<h:message for="username"></h:message>
</h:form>
</f:view>

faces-config.xml配置:
<faces-config>

<managed-bean>
<managed-bean-name>login</managed-bean-name>
<managed-bean-class>com.hnisi.item.demo.Login</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>userList</managed-bean-name>
<managed-bean-class>com.hnisi.item.demo.UserList</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/hello.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/error.jsp</to-view-id>
</navigation-case>
</navigation-rule>

</faces-config>

报错::::!!!!!!
严重: #{login.check }: javax.faces.el.MethodNotFoundException: check : com.hnisi.item.demo.Login.check ()
javax.faces.FacesException: #{login.check }: javax.faces.el.MethodNotFoundException: check : com.hnisi.item.demo.Login.check ()
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:744)


请问这是什么原因,怎样调用那个验证的方法????
------解决方案--------------------
问题是找不到 check这个方法....

建议:login.check  这个login要不要大写  毕竟<h:commandButton  这个action 是类.方法名
  相关解决方案