我对此错误有疑问。我正在做关于jsf,hibernate,spring和maven的教程。
以下是教程的链接。 http://www.onlinetechvision.com/?p=566
以下是我收到的错误消息。
Nov 30, 2012 2:16:56 PM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: Received 'javax.el.MethodNotFoundException' when invoking action listener '#{userMB.deleteUser(user.id)}' for component 'deleteUser'
Nov 30, 2012 2:16:56 PM javax.faces.event.MethodExpressionActionListener processAction
SEVERE: javax.el.MethodNotFoundException: Method not found: com.otv.managed.bean.UserManagedBean@50e0de15.deleteUser(java.lang.Integer)
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:84)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773)
at javax.faces.component.UICommand.broadcast(UICommand.java:296)
at javax.faces.component.UIData.broadcast(UIData.java:911)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1255)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:334)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Nov 30, 2012 2:16:56 PM com.sun.faces.context.AjaxExceptionHandlerImpl log
SEVERE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt5:users:0, Message=Method not found: com.otv.managed.bean.UserManagedBean@50e0de15.deleteUser(java.lang.Integer)
Nov 30, 2012 2:16:56 PM com.sun.faces.context.AjaxExceptionHandlerImpl log
SEVERE: Method not found: com.otv.managed.bean.UserManagedBean@50e0de15.deleteUser(java.lang.Integer)
javax.faces.event.AbortProcessingException: Method not found: com.otv.managed.bean.UserManagedBean@50e0de15.deleteUser(java.lang.Integer)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:178)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:84)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:773)
at javax.faces.component.UICommand.broadcast(UICommand.java:296)
at javax.faces.component.UIData.broadcast(UIData.java:911)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1255)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:334)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: javax.el.MethodNotFoundException: Method not found: com.otv.managed.bean.UserManagedBean@50e0de15.deleteUser(java.lang.Integer)
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:245)
at org.apache.el.parser.AstValue.invoke(AstValue.java:271)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
... 26 more
这是我的'UserManbedBean.java'文件。
package com.otv.managed.bean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import org.springframework.dao.DataAccessException;
import com.otv.model.User;
import com.otv.user.service.IUserService;
/**
*
* User Managed Bean
*
* @author onlinetechvision.com
* @since 25 Mar 2012
* @version 1.0.0
*
*/
@ManagedBean(name="userMB")
@RequestScoped
public class UserManagedBean implements Serializable {
private static final long serialVersionUID = 1L;
private static final String SUCCESS = "success";
private static final String ERROR = "error";
//Spring User Service is injected...
@ManagedProperty(value="#{UserService}")
IUserService userService;
List<User> userList;
private int id;
private String name;
private String surname;
/**
* Add User
*
* @return String - Response Message
*/
public String addUser() {
try {
User user = new User();
user.setId(getId());
user.setName(getName());
user.setSurname(getSurname());
getUserService().addUser(user);
return SUCCESS;
} catch (DataAccessException e) {
e.printStackTrace();
}
return ERROR;
}
/**
* delete User
* @param id
*/
public void deleteUser(int id) {
User user =(User)userService.getUserById(id);
getUserService().deleteUser(user);
}
public String deleteAction(User user){
userList.remove(user);
return null;
}
/**
* Update User
* @param id
*/
public void updateUser(int id){
User user = userService.getUserById(id);
user.setName(getName());
user.setSurname(getSurname());
getUserService().updateUser(user);
}
/**
* Reset Fields
*
*/
public void reset() {
this.setId(0);
this.setName("");
this.setSurname("");
}
/**
* Get User List
*
* @return List - User List
*/
public List<User> getUserList() {
userList = new ArrayList<User>();
userList.addAll(getUserService().getUsers());
return userList;
}
/**
* Get User Service
*
* @return IUserService - User Service
*/
public IUserService getUserService() {
return userService;
}
/**
* Set User Service
*
* @param IUserService - User Service
*/
public void setUserService(IUserService userService) {
this.userService = userService;
}
/**
* Set User List
*
* @param List - User List
*/
public void setUserList(List<User> userList) {
this.userList = userList;
}
/**
* Get User Id
*
* @return int - User Id
*/
public int getId() {
return id;
}
/**
* Set User Id
*
* @param int - User Id
*/
public void setId(int id) {
this.id = id;
}
/**
* Get User Name
*
* @return String - User Name
*/
public String getName() {
return name;
}
/**
* Set User Name
*
* @param String - User Name
*/
public void setName(String name) {
this.name = name;
}
/**
* Get User Surname
*
* @return String - User Surname
*/
public String getSurname() {
return surname;
}
/**
* Set User Surname
*
* @param String - User Surname
*/
public void setSurname(String surname) {
this.surname = surname;
}
}
这是我的'success.xhtml'文件
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Welcome to OTV_JSF_Spring_Hibernate_Project</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="USERs : "></h:outputText>
<p:dataTable id="users" var="user" value="#{userMB.userList}" style="width: 10%">
<p:column>
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<h:outputText value="#{user.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Surname" />
</f:facet>
<h:outputText value="#{user.surname}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Action" />
</f:facet>
<p:commandButton id="deleteUser" value="Delete" actionListener="#{userMB.deleteUser(user.id)}" action="#{userMB.deleteAction(user)}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Action" />
</f:facet>
<p:commandButton id="updateUser" value="update" actionListener="#{userMB.updateUser(user.id)}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
这是我的UserService.java文件
package com.otv.user.service;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;
import com.otv.model.User;
import com.otv.user.dao.IUserDAO;
/**
*
* User Service
*
* @author onlinetechvision.com
* @since 25 Mar 2012
* @version 1.0.0
*
*/
@Transactional(readOnly = true)
public class UserService implements IUserService {
// UserDAO is injected...
IUserDAO userDAO;
/**
* Add User
*
* @param User user
*/
@Transactional(readOnly = false)
@Override
public void addUser(User user) {
getUserDAO().addUser(user);
}
/**
* Delete User
*
* @param User user
*/
@Transactional(readOnly = false)
@Override
public void deleteUser(User user) {
getUserDAO().deleteUser(user);
}
/**
* Update User
*
* @param User user
*/
@Transactional(readOnly = false)
@Override
public void updateUser(User user) {
getUserDAO().updateUser(user);
}
/**
* Get User
*
* @param int User Id
*/
@Override
public User getUserById(int id) {
return getUserDAO().getUserById(id);
}
/**
* Get User List
*
*/
@Override
public List<User> getUsers() {
return getUserDAO().getUsers();
}
/**
* Get User DAO
*
* @return IUserDAO - User DAO
*/
public IUserDAO getUserDAO() {
return userDAO;
}
/**
* Set User DAO
*
* @param IUserDAO - User DAO
*/
public void setUserDAO(IUserDAO userDAO) {
this.userDAO = userDAO;
}
}
这是我的UserDAO.java文件
package com.otv.user.dao;
import java.util.List;
import com.otv.model.User;
import org.hibernate.SessionFactory;
/**
*
* User DAO
*
* @author onlinetechvision.com
* @since 25 Mar 2012
* @version 1.0.0
*
*/
public class UserDAO implements IUserDAO {
private SessionFactory sessionFactory;
/**
* Get Hibernate Session Factory
*
* @return SessionFactory - Hibernate Session Factory
*/
public SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* Set Hibernate Session Factory
*
* @param SessionFactory - Hibernate Session Factory
*/
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
/**
* Add User
*
* @param User user
*/
@Override
public void addUser(User user) {
getSessionFactory().getCurrentSession().save(user);
}
/**
* Delete User
*
* @param User user
*/
@Override
public void deleteUser(User user) {
getSessionFactory().getCurrentSession().delete(user);
}
/**
* Update User
*
* @param User user
*/
@Override
public void updateUser(User user) {
getSessionFactory().getCurrentSession().update(user);
}
/**
* Get User
*
* @param int User Id
* @return User
*/
@Override
public User getUserById(int id) {
List list = getSessionFactory().getCurrentSession()
.createQuery("from User where id=?")
.setParameter(0, id).list();
return (User)list.get(0);
}
/**
* Get User List
*
* @return List - User list
*/
@Override
public List<User> getUsers() {
List list = getSessionFactory().getCurrentSession().createQuery("from User").list();
return list;
}
}
感谢您的阅读。
答案 0 :(得分:2)
您需要在函数int
中将Integer
替换为public void deleteUser(int id)
。
JSF仅适用于Objects,不能使用原始类型。
答案 1 :(得分:-1)
FORCE类代理。 Spring使用基于代理的aop,你的托管bean实现了一个接口,因此使用了jdk动态代理而不是类代理。
删除接口实现(Serializable),导致Spring返回CGLIB,或者强制强制CGLIB代理,声明:
<aop:config proxy-target-class="true" />