Adnan
Adnan

Reputation: 4607

Displaying h:columns in different rows

I am displaying values from database table using h:datatable, one tupple is displaying in one row of jsf page but i want to display every field in seperate row of jsf page. How can i achieve this?

Thanks in advance.

I am having the following code in jsf page.

<h:dataTable value="#{tableBean.pc}" var="p">

<h:column>
    <h:graphicImage value="/resources/images/#{p.pimagename}" />
</h:column>

<h:column>
    <h:outputText value="#{p.pname}" />
</h:column>

<h:column>
    <h:outputText value="#{p.pprice}" />
</h:column>

<h:column>
    <h:outputText value="#{p.pqtyavail}" />
</h:column>

</h:dataTable>

Upvotes: 0

Views: 1875

Answers (1)

BalusC
BalusC

Reputation: 1109665

Either change your datamodel so that you have all tuple fields as a single entry of an one-dimensional List:

List<List<String>> tuples = getItSomehow();
List<String> fields = new ArrayList<String>();

for (List<String> tuple : tuples) {
    fields.addAll(tuple);
}

and use it instead.

<h:dataTable value="#{bean.fields}" var="field">
    <h:column>#{field}</h:column>
</h:dataTable>

Or, bring in the HTML <br/> element to put each tuple field in a separate line in a single column.

<h:dataTable value="#{bean.tuples}" var="tuple">
    <h:column>#{tuple[0]}<br/>#{tuple[1]}<br/>#{tuple[2]}</h:column>
</h:dataTable>

Upvotes: 1

Related Questions