Rich Layer 4 Columns

I need a dynamic number of columns. Richfaces ships it with <rich:columns> in richfaces 3.3.3-final, but for Richfaces 4 they recommend <c:forEach> .

from: Foreach

I can not get it to work correctly. Since I cannot depend on var on a datatable, I cannot figure out how to feed <c:forEach> correct list of columns. (Each line has its own values, but the headers are the same)

Basically, the data I want to display is a list with rows of size x, each row has a list of column values ​​with size y. But how can <c:forEach> tell the bean which row it should, so that I can correct the correct columns?

n / a 4j: repeat

I do not want to reinvent the wheel because I need frozen columns and many other functions. It was considered creating the html table in this way and using jQuery for other functions. However, it would be hopeless to support and work hard.

I also looked at creating from a dynamic bean creating children dynamically, but I don't like it at all. This should be a last resort.

Usage: Tomcat 7, Servlet 3.0, JSF 2.1x - Mojarra, Richfaces 4.x

Update

Good, so I will get some results. However, my headers are not displayed. The values ​​are displayed fine, but not the headers. Does some problem make them iterate or something else?

  <rich:dataTable value="#{controller.rows}" var="row"> <c:forEach items="#{controller.columns}" var="column"> <rd:column id="name" width="250"> <f:facet name="header"> <h:outputText value="#{row.myArrayList[column].header}" /> </f:facet> <h:inputText value="#{row.myArrayList[column].value}" disabled="#{row.myArrayList[column].open}"/> </rd:column> </c:forEach> </rich:dataTable> 
+4
source share
1 answer

<c:forEach> really the best you can get. <ui/a4j:repeat> will not work as it does when rendering the view, while the UIData component really needs UIColumn children, not UIRepeat children.

To make <c:forEach> work, you need to provide it with a list / map of all property names (and in the case of a map, perhaps also a title label). Here is an example of a specific example, assuming Item has id , name and value properties and that #{bean.itemPropertyNames} returns a List<String> with these property names.

 <rich:dataTable value="#{bean.items}" var="item"> <c:forEach items="#{bean.itemPropertyNames}" var="itemPropertyName"> <rich:column> #{item[itemPropertyName]} </rich:column> </c:forEach> </rich:dataTable> 

If you also need to show the column headings, it is best to have Map<String, String> where the key represents the name of the property and the value represents the value of the header.

 <rich:dataTable value="#{bean.items}" var="item"> <c:forEach items="#{bean.itemProperties}" var="itemProperty"> <rich:column> <f:facet name="header">#{itemProperty.value}</f:facet> #{item[itemProperty.key]} </rich:column> </c:forEach> </rich:dataTable> 

In any case, the only drawback is that #{bean} of <c:forEach items> may not be visible in this construct. It will be recreated for each request, if you do not disable partial state saving. It must be the scope of the request (or session or application). Note that this does not have to be the same bean as in <rich:dataTable value> .

See also:

+6
source

All Articles