![](/img/trans.png)
[英]How to make the conversion of a project with managed beans to one with CDI Beans?
[英]How to bind facelets to CDI beans?
我有一个简单的xhtml页面,其中:
<h:form>
<p:dataTable var="customer" value="#{customersTableBackingBean.allCustomers}">
<p:column headerText="First Name">
<h:outputText value="#{customer.contactFirstName}" />
</p:column>
<p:column headerText="City">
<h:outputText value="#{customer.city}" />
</p:column>
</p:dataTable>
</h:form>
当我的CustomersTableBackingBean.java如下时:
@ManagedBean
@RequestScoped
public class CustomersTableBackingBean {
@EJB(name = "#{customersService}")
CustomersService customersService;
public List<Customers> getAllCustomers(){
return customersService.getAllCustomers();
}
public String sayHello(){
return "Hello from a managed bean!";
}
}
我按预期在index.xhtml上从数据库中获取了一些数据。
但是,当我将@ManagedBean批注更改为@Named并导入: javax.inject.Named时 ,index.xhtml中没有数据。
这种结构有什么问题?
如何使用CDI bean而不是JSF ManagedBean?
(我有一个beans.xml文件,它是空的。)
我将回答我自己的问题:
beans.xml转到web-inf文件夹而不是meta-inf!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.