Вопрос

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.

Другие советы

This is my problem.

Change the imports and works:

import javax.faces.bean.ManagedBean;

import javax.faces.bean.RequestScoped;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top