How to show string array in primefaces datatable?

i'm working on a project with JSF and PrimeFaces. In this project i have to show a string array on datatable.

View:

<p:dataTable id="table" var="String" value="#{readData.tuples}" scrollRows="50" scrollable="true" liveScroll="true" scrollHeight="150">
     <h:outputText value="String"/>
</p:dataTable>

Bean:

List<String[]> allRows = new ArrayList<>();
List<String> tuples = new ArrayList<>();

public String fill() {
    String s = "";
    for (String[] tuple : allRows) {
        for (String string : tuple) {
            s += string + "   ";
            tuples.add(s);
        }
        s = "";
    }
    return "tables.xhtml";
}

I want to show allRows String[] list as columns and rows. Every string array on list will be a row, every element of string[] will be in columns. Or showing tuples list on datatable as every string as a row, it'll work too.

How can i do that?

Upvotes: 0

Views: 4731

Answers (1)

Gwiazdek
Gwiazdek

Reputation: 169

try

<p:dataTable id="table" var="string" value="#{readData.tuples}" scrollRows="50" scrollable="true" liveScroll="true" scrollHeight="150">
<p:column>
  <h:outputText value="#{string}"/>
</p:column>

</p:dataTable>

Upvotes: 2

Related Questions