0

i have a problem with my primefaces datatable, rows are empty.

<h:body>
<ui:composition template="../shared/commonLayout.xhtml">
            <ui:define name="content">
    <h:form>
        <p:dataTable id="users" var="user" value="#{UserManagedBean.userList}" style="width: 40%">
            <p:column>
                <f:facet name="header">
                    <h:outputText value="FirstName" />
                </f:facet>
                <h:outputText value="#{user.firstname}" />
            </p:column>
        </p:dataTable>
    </h:form>
    </ui:define>
    </ui:composition>
</h:body>
@ManagedBean(name = "UserManagedBean")
@SessionScoped
public class UserManagedBean {
//..
/**
     * Get Users List.
     * 
     * @return List - User List
     */
    public final List<User> getUserList() {
        userList = new ArrayList<User>();
        userList.addAll(getUserService().getItems());
        return userList;
    }
}

i'm using spring, hibernate, jsf managed beans. can somebody help me please? enter image description here

Saidi omar
  • 81
  • 2
  • 10
  • Is your userList populated properly from the bean? – Parkash Kumar Jan 06 '15 at 13:32
  • yes,i have 2 elements in the database and my user list is charged successfully – Saidi omar Jan 06 '15 at 13:34
  • 1
    Post the code of `UserManagedBean`, without it we can only guess. Are there any errors in the console? Is the bean's name with capital `U`, or maybe `userManagedBean`? – Predrag Maric Jan 06 '15 at 13:41
  • @ManagedBean(name = "UserManagedBean") @SessionScoped public class UserManagedBean {/** * Get Users List. * * return List - User List */ public final List getUserList() { userList = new ArrayList(); userList.addAll(getUserService().getItems()); return userList; } – Saidi omar Jan 06 '15 at 13:43
  • Its a long shot but try to use columns like this – Kiki Jan 06 '15 at 13:44
  • And the rest of the code? Anything involving `userList`? – Predrag Maric Jan 06 '15 at 13:45
  • @ManagedBean(name = "UserManagedBean") @SessionScoped public class UserManagedBean {/** * Get Users List. * * return List - User List */ public final List getUserList() { userList = new ArrayList(); userList.addAll(getUserService().getItems()); return userList; } – Saidi omar Jan 06 '15 at 13:45
  • same problem with p:column headertext="... – Saidi omar Jan 06 '15 at 13:47
  • You could put that code in the question, not the comment, it's almost useless here. – Predrag Maric Jan 06 '15 at 13:54
  • Just saying as a side note : What is need to use the `addAll()` method of the said `java.util.List`? You can just assign a return value arriving from the service layer (EJBs or whatever). Are you extremely sure about the return value of this service method - `getUserService().getItems()`? Does the `getItems()` method return some concrete rows hereby not a `null` or empty list? – Tiny Jan 06 '15 at 14:35
  • ![][1] [1]: http://i.stack.imgur.com/hnZpG.png – Saidi omar Jan 06 '15 at 14:47

2 Answers2

0

The code you have posted should work if:

  • getUserList() returns some rows, filled with some data
  • User class has a field firstname with getter and setter (note the case, n is lowercase in your column)
  • That firstname field is populated (not empty)

Can you verify the above?

Predrag Maric
  • 23,938
  • 5
  • 52
  • 68
0

A few things to correct in your code:

  1. Don't do business logic in the getter; move that code into a @PostConstruct

  2. Don't back a page with a @SessionScoped bean; it's a design-smell and almost never ends well. Use the @RequestScoped or @ViewScoped instead.

  3. Everything outside a <ui:composition/> is ignored by the facelets engine. What that means is that all the tags you've defined outside it will have no effect (the <h:body/>) for example

Related Reading:

Community
  • 1
  • 1
kolossus
  • 20,559
  • 3
  • 52
  • 104