I am trying to create a basic datatable which fetches the value from database and displays in the table format. However while I try to debug I see that managed bean functions are not being called. Below is the code
list.xhtml:
<h:body>
<h3>Expense list</h3>
<h:dataTable value="#{userMB.entries}" var="e" styleClass="table"
headerClass="table-header" rowClasses="table-odd-row,table-even-row">
<h:column>
<f:facet name="header">Date</f:facet>
#{e.date}
</h:column>
</h:dataTable>
</h:body>
UserMB.java
@ManagedBean
@SessionScoped
public class UserMB {
private List<Entry> entries;
@EJB(mappedName = "entryServices")
private EntryServices entryServices;
public UserMB() {
}
@PostConstruct
public void init() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context
.getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
User user = (User) httpSession.getAttribute("user");
entries = new ArrayList<Entry>();
entries = entryServices.getEntryByUser(user);
}
public List<Entry> getEntries() {
return entries;
}
public void setEntries(List<Entry> entries) {
this.entries = entries;
}
public EntryServices getEntryServices() {
return entryServices;
}
public void setEntryServices(
EntryServices entryServices) {
this.entryServices = entryServices;
}
}
I don't see any error in the code or the facelet, sometimes I not choose the right package for the annotation that must be javax.faces.ManagedBean
and javax.faces.SessionScoped
otherwise the bean is never created.
In glassfish when I use a EJB in the ManagedBean it need to be serialized could you try this.
I hope this could help you.