I have a simple xhtml page with:
<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>
When my CustomersTableBackingBean.java is as follows:
@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!";
}
}
I see some data fetched from the database, on index.xhtml as expected.
However when I change the @ManagedBean annotation to @Named and import: javax.inject.Named there is no data in index.xhtml.
What is wrong with this structure?
How can I use a CDI bean instead of a JSF ManagedBean?
( I have a beans.xml file which is empty. )
I will answer my own question:
beans.xml goes to web-inf folder not to meta-inf !