rich:dataTable with dynamic columns
axelmotyka Jan 30, 2009 4:50 AMIam new to richfaces, so maybe this is a simple problem - but i searched the forum i didnt found the right answer for me.
The post is a little bit longer, but i hope everyone understands what i mean.
My Problem is: I have a table with 2 default columns and some dynamic columns.
In other words, a user selects a logbook -> an new LogbookReport is created and should be shown in the the dataTable. This specific logbook has always 5 dynamic columnes - other logbooks have 5 or more. But all logbooks have 2 fixed columns. I will add more "meta" data to LogbookReport later on - but that doesnt touch my problem.
I built up a collection class for all values:
public class LogbookReport { private List<LogbookReportRecord> records = null; public LogbookReport() { initRecords(); } public List<LogbookReportRecord> getRecords() { return records; } public void setRecords(List<LogbookReportRecord> records) { this.records = records; } private void initRecords() { records = new ArrayList<LogbookReportRecord>(); LogbookReportRecord rec; ArrayList<String> values = new ArrayList<String>(); //Dynamic values values.add("10"); values.add("100"); values.add("1000"); values.add("10000"); values.add("10.10"); rec = new LogbookReportRecord("01.01.2009", values, "Kommentar 1"); records.add(rec); values = new ArrayList<String>(); values.add("20"); values.add("200"); values.add("2000"); values.add("20000"); values.add("20.20"); rec = new LogbookReportRecord("02.01.2009", values, "Kommentar 2"); records.add(rec); } }
And the values are:
public class LogbookReportRecord { private String timestamp; private List<String> values = new ArrayList<String>(); private String comment; public LogbookReportRecord() { } public LogbookReportRecord(String timestamp, List<String> values, String comment) { this.timestamp = timestamp; this.values = values; this.comment = comment; } public String getTimestamp() { return timestamp; } public void setTimestamp(String timestamp) { this.timestamp = timestamp; } public List<String> getValues() { return this.values; } public void setValues(List<String> values) { this.values = values; } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } }
Then i try to show the data:
<rich:dataTable var="record" value="#{logbookReport.records}"> <rich:columnGroup> <rich:column> <h:outputText value="#{record.timestamp}" /> </rich:column> <!-- for each wont work--> <c:forEach items="#{record.values}" var="value"> <rich:column> <h:outputText value="#{value}" /> </rich:column> </c:forEach> <!-- rich:columns wont work --> <!-- <rich:columns value="#{record.values}" var="value" index="index"> <h:outputText value="#{value}" /> </rich:columns>--> <rich:column> <h:outputText value="#{record.comment}" /> </rich:column> </rich:columnGroup> </rich:dataTable>
Where is my mistake?
Is it not possible to iterate through a collection inside a collection?