Creating HtmlDataTable + Subtable programmatically / Problem
flo_d Feb 8, 2009 1:56 PMHi,
when I try to create a HtmlDataTable progrmmatically and than add a HtmlSubTable, the getRowData()-method of the sub table doesn't work as expected.
Here's the code I have in the view:
<rich:dataTable id="dtb_frm_content" binding="#{report.reportItemsTable}" />
And here's the code if have in the getReportItemsTable of the backing bean:
//create data table this.reportItemsTable = new HtmlDataTable(); //set the value of the table => a list of OrderedReportRow-objects (see below) this.reportItemsTable.setValue(this.getOrderedReportRowOfCurrentReport()); //add columns to datatable: ... //create sub table and set value expression this.subTable = new HtmlSubTable(); ValueExpression valueExpressionForOrderedReportRows = FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression( FacesContext.getCurrentInstance().getELContext(), "#{orderedReportRow.reportRows}", ArrayList.class ); this.subTable.setValueExpression("value", valueExpressionForOrderedReportRows); //add columns to sub table ... //create column for an edit link HtmlColumn columnEdit = new HtmlColumn(); //add link to column to edit HtmlAjaxCommandLink linkEdit = new HtmlAjaxCommandLink(); linkEdit.setId("edit"); linkEdit.setValue("edit"); linkEdit.setActionExpression( FacesContext. getCurrentInstance(). getApplication(). getExpressionFactory(). createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{report.editRowStart}", String.class, new Class[0] ) ); //add edit column to sub table subTable.getChildren().add(columnEdit); //add sub table to table this.reportItemsTable.getChildren().add(subTable);
When I click the edit link, the editRowStart()-method is called as expected:
public void editRowStart(){ this.currentRow = (ReportRow)this.subTable.getRowData(); }
But the row is set correctly only the first time, when I click the edit link in another row, the currentRow is still the same than after the first click. I think I have to bind the subtable to the backing bean, but I couldn't find a setBinding-attribute in the SubTable class (although I know that a binding attribute exists for the subTable-tag).
Can anybody help me with this?
Thanks