【发布时间】:2017-08-09 14:52:06
【问题描述】:
我有一个从数据库表中自动构建的实体类(Buyer),它具有所有的 setter 和 getter。我还在其中添加了一个 JSF 托管 Bean(BuyerBean) 和一个实体管理器。
@ManagedBean
@RequestScoped
public class BuyerBean {
private EntityManager entitymanager;
public BuyerBean() {
}
public void init(){
entitymanager=Persistence.createEntityManagerFactory("WebApplication3").createEntityManager();
}
public void newrec(){
entitymanager.getTransaction().begin();
Buyer b =new Buyer();
b.setBuyerId(66);
entitymanager.persist(b);
entitymanager.getTransaction().commit();
}
}
而我的JFS是这样的,很简单,只是为了测试:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="click 1" action="#{buyerBean.newrec()}"/>
</h:form>
</h:body>
</html>
每次浏览器都会出现此错误: java.lang.NullPointerException
我的发起人有问题吗?如果有,请写一段代码
【问题讨论】:
-
我已经读过那篇文章,但 jsf 和 xhtml 没有任何相关问题