0

I am trying to display below list of list of object in datatable. But nothing is showing up. Help is very much appreciated!

public class TimrsDisplayBean {

    private static final long serialVersionUID = 1L;
    private String teamName = "";
    private String teamType = "";
    private boolean reported;
    private boolean noProd;
    private boolean missing;

    public String getTeamName() {
        return teamName;
    }

    public void setTeamName(String teamName) {
        this.teamName = teamName;
    }

    public String getTeamType() {
        return teamType;
    }

    public void setTeamType(String teamType) {
        this.teamType = teamType;
    }
    public boolean getReported() {
        return reported;
    }
    public void setReported(boolean reported) {
        this.reported = reported;
    }

    public boolean getNoProd() {
        return noProd;
    }

    public void setNoProd(boolean noProd) {
        this.noProd = noProd;
    }

    public boolean getMissing() {
        return missing;
    }

    public void setMissing(boolean missing) {
        this.missing = missing;
    }
}

XHTML FILE

<p:dataTable value="#{dashboardMBean.timrsDisplayDataList}" var="var" rowIndexVar="row"
                                styleClass="large-card-datatable alternatingRowTable no-border nowrap">
                                <f:facet name="header">
                                    <span class="updateDate"> </span>
                                </f:facet>
                                <p:column headerText="Type" value=" #{dashboardMBean.timrsDisplayDataList[0]}" columnIndexVar="i">   
                                    #{var[i].teamType}
                                </p:column>
                                <p:column headerText="Type" value=" #{dashboardMBean.timrsDisplayDataList[0]}" columnIndexVar="i">   
                                    #{var[i].teamName}
                                </p:column>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Anu
  • 11
  • 2
  • 4
  • List> timrsDisplayDataList = new ArrayList>(); is list I am trying to display – Anu Aug 03 '16 at 13:05
  • What is `columnIndexVar`? I don't think that attribute exists for a `p:column`. – Jasper de Vries Aug 03 '16 at 13:40
  • I am not using rowIndexVar. I can remove it was just trying diff things. – Anu Aug 03 '16 at 13:50
  • Same goes for `value`. See what happens if you simply put `#{var}`. That should give you the `toString()` of whatever is in `var`. If not, please post the relevant parts of your `dashboardMBean`. – Jasper de Vries Aug 03 '16 at 13:56
  • #{var} display the list of objects but not the value of teamType in the object. If I use #{var[0].teamType} it shows the teamType of first object in the list but not the rest of objects in the list. – Anu Aug 03 '16 at 14:23
  • In that case, what exactly is your problem? Are you looking for JSTL forEach? http://stackoverflow.com/questions/2148658/iterate-over-elements-of-list-and-map-using-jstl-cforeach-tag – Jasper de Vries Aug 03 '16 at 14:30
  • 1
    Duplicate: http://stackoverflow.com/questions/20007189/dynamic-columns-with-listlist-in-pdatatablepcolumns? – Kukeltje Aug 03 '16 at 21:28
  • @Kukeltje Interesting. NetBeans does not offer those attributes. I'm not sure if this is a duplicate.. Not even sure what the problem is. Looks like simply using a single list is the way to go. – Jasper de Vries Aug 04 '16 at 08:37

1 Answers1

0

Please support full code parts if possible. Your datatable tag doesn't even finish.

Beside that, it seems like you've done too much work. Did you try to calculate the row indices by yourself? Not needed. The basic column definiton is more comfortable. Use your defined variable var to name each element/row as shown in the Primefaces showcase: http://www.primefaces.org/showcase/ui/data/datatable/basic.xhtml

In your case, it will be something like

<p:column headerText="Type">
    <h:outputText value="#{var.teamType}"/>
</p:column>

Plus, as Jasper De Vries said correctly, there is no attribute called columnIndexVar. Remove it to prevent strange behaviour.

If this is not enough, you need to share some more code of your ManagedBean. Not sure if your posted java class represent your Bean, but if so, you need to declare it as a ManagedBean like

@ManagedBean(name = "timrsDisplayBean)
@SessionScoped
public class TimrsDisplayBean {

I hope this helps!

  • Are you implying to use a single (non nested) list? – Jasper de Vries Aug 04 '16 at 08:38
  • I personally would recommend a solution like this. I am not a fan of (multiple..!) nested data structures. If you have to insist on a nested list, I would suggest to use something like a `RowExpansion` to show the details respectively the nested list objects. But, honestly, I miss several information/source codes in this question, e.g. the setter/getter of `timrsDisplayDataList` – chaeschuechli Aug 04 '16 at 11:27