1

I'm using a to print in two strings in two columns as in the following code:

<h:panelGrid
            columns="2" border="1">
        <ui:repeat
            value="#{bean.selectedLocales}"
                    var="locale">
            <h:outputText value="#{msg[locale]}"/>
        </ui:repeat>
</h:panelGrid>

The above prints two locales en and de taken from a list in a same column although I use ui:repeat and columns="2" in <h:panelGrid>. How can I make it to print in two different columns?

Rajath
  • 2,178
  • 6
  • 32
  • 38
  • @Daniel - Nope, not working! – Rajath Jan 28 '13 at 09:41
  • 2
    possible duplicate of http://stackoverflow.com/questions/8945544/uirepeat-and-hpanelgrid – cubbuk Jan 28 '13 at 09:48
  • @cubbuk - The above solution is displaying it in 2 rows instead of 2 columns! – Rajath Jan 28 '13 at 09:58
  • 1
    You can replace ui:repeat with c:forEach, but this might create problem later on when the number of selectedLocales change dynamically. Otherwise you might wanna check the following article http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable – cubbuk Jan 28 '13 at 10:05
  • possible duplicate of [create table columns dynamically in JSF](http://stackoverflow.com/questions/11280688/create-table-columns-dynamically-in-jsf) – BalusC Jan 28 '13 at 11:41

1 Answers1

1

The reason is that your h:panelGrid contains only one nested element: ui:repeat, and it cannot show the one element in two columns. What about doing a dynamic dataTable of it using the vendor specific columns eg. p:columns, ice:columns in the JSF page and javax.faces.model.ListDataModel in the managed bean?

Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
  • Thanks! But the above solution is displaying it in 2 rows instead of 2 columns. Any idea what to do? – Rajath Jan 28 '13 at 09:55
  • Is it mandatory to use `ListDataModel` in the managed bean when using with `h:dataTable`? – Rajath Jan 28 '13 at 10:03
  • I don't see other solution if you want to show a non-constant number of columns in a dataTable. – Donato Szilagyi Jan 28 '13 at 10:04
  • Is it not possible with a simple `List` of items? – Rajath Jan 28 '13 at 10:06
  • If I use anything in the , the list of values are displayed in new rows in the same column. But how do I display each item of a list is separate columns? – Rajath Jan 28 '13 at 10:12
  • `h:columns` [doesn't exist](http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/). – BalusC Jan 28 '13 at 11:41