jsf 报错 javax.faces.el.MethodNotFoundException

J2EE 码拜 10年前 (2015-04-15) 2402次浏览 0个评论

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)

请问这是什么原因,怎样调用那个验证的方法????

jsf 报错  javax.faces.el.MethodNotFoundException
40分
问题是找不到 check这个方法….

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

jsf 报错  javax.faces.el.MethodNotFoundException
引用 1 楼 shijing266 的回复:

问题是找不到 check这个方法….

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

不行啊~~ 改了一样的错误!  
我这里已经绑定了类:
<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>
我试着设置静态方法一样不行

jsf 报错  javax.faces.el.MethodNotFoundException
引用 2 楼 itlijunjie 的回复:
Quote: 引用 1 楼 shijing266 的回复:

问题是找不到 check这个方法….

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

不行啊~~ 改了一样的错误!  
我这里已经绑定了类:
<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>
我试着设置静态方法一样不行

设置<h:commandButton 的属性immediate=true试试

jsf 报错  javax.faces.el.MethodNotFoundException
如果还不行,看看这个http://wenku.baidu.com/link?url=X1dP0ERY8QZpuFBQiItdVAaK99ApCcanTyoNJSBL5nt–q1NruresluC3ytyplrnGVCr-tOt7TRhSz_rIX7dkIKo2bP5hgWE_zoRm3WY8hG
jsf 报错  javax.faces.el.MethodNotFoundException
我终于找到错误的根源了,
jsp文件里:
错误:<h:commandButton value=”登录” action=”#{login.verify }”></h:commandButton>
正确:<h:commandButton value=”登录” action=”#{login.verify}”></h:commandButton>

有空格就找不到方法了

jsf 报错  javax.faces.el.MethodNotFoundException
引用 4 楼 shijing266 的回复:

如果还不行,看看这个http://wenku.baidu.com/link?url=X1dP0ERY8QZpuFBQiItdVAaK99ApCcanTyoNJSBL5nt–q1NruresluC3ytyplrnGVCr-tOt7TRhSz_rIX7dkIKo2bP5hgWE_zoRm3WY8hG

受教! thanks!


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明jsf 报错 javax.faces.el.MethodNotFoundException
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!