私は単純な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に変更してimport: javax.inject.Named すると、 index.xhtmlにデータがありません。
この構造の何が問題なのですか?
JSF ManagedBean の代わりに CDI Bean を使用するにはどうすればよいですか?
(空の beans.xml ファイルがあります。)