有关JSF-JPA集成报 Could not find a setter for property message in class ..问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有关JSF-JPA集成报 Could not find a setter for property message in class ..问题相关的知识,希望对你有一定的参考价值。
JSF做前端,后台接收数据,用JPA处理数据时就报错代码如下:
JSF端:index.jsp
<body>
<f:view>
<h2>请输入要查询的用户ID</h2>
<h:form id="f">
名称ID:<h:inputText value="#user.userid" id="userid">
</h:inputText>
<h:commandButton action="#useraction.getById" value="确定">
</h:commandButton>
</h:form>
</f:view>
</body>
</html>
JSF配置文件:
<managed-bean>
<managed-bean-name>useraction</managed-bean-name>
<managed-bean-class>com.weiztek.action.UserAction</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/pages/index.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/pages/show.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
JPA代码:
package com.weiztek.action;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import com.wiztek.bean.User;
public class UserAction
public EntityManagerFactory getEMFactory()
EntityManagerFactory f=Persistence.createEntityManagerFactory("ss");
return f;
public String getById()
int id=new Integer(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get( "f:userid"));
//EntityManager em=getEMFactory().createEntityManager();
EntityManagerFactory f=Persistence.createEntityManagerFactory("ss");//加上这句话就报错
EntityManager em=f.createEntityManager();
User u=em.find(User.class, id);
System.out.println(id);
em.close();
f.close();
return "success";
你看下你给的代码最后一个类,报错的这句话
EntityManagerFactory f=Persistence.createEntityManagerFactory("ss");
这里定义了一个EntityManagerFactory对象,然后把值ss放到里面,而一般的类做“放入”操作的时候都要用到setXX()方法的,而你上面只有EntityManagerFactory getEMFactory()也就是get()方法,却没有set()方法,所以在你做set操作的时候却有没有set方法,自然会报出“Could not find a setter for property message in class ..”这样的错误提示本回答被提问者和网友采纳 参考技术B 名称ID:<h:inputText value="#user.userid" id="userid">
没看见这个user 绑定后台哪个bean啊。
接口请求报Could not marshal异常解决
1.问题:
在请求自己写的java api接口时,发现报了如下错误:
2.原因:
浏览器本身对响应格式解析不支持,导致无法解析,属于正常现象,并非代码问题,更换postman工具或代码直接调用即可:
以上是关于有关JSF-JPA集成报 Could not find a setter for property message in class ..问题的主要内容,如果未能解决你的问题,请参考以下文章
怎样解决电脑开机出现this application failed to start because it could not fi
Got fatal error 1236 from master when reading data from binary log: 'Could not find first log fi
解决报错:IncompleteElementException: Could not find result map...