|
Hi, I am new to JSF and I need some help: I use a datatable with a dynamic number of columns. This is generally working well like in the
openDataTable.jsp sample. Now I have to render the first column as a checkbox (
<h:selectBooleanCheckbox> ). In the openDataTable.jsp sample a flag is used to
check whether a column should be rendered as <h:inputText> or
<h:outputText>. Should I use also a flag to determine the UIComponent
to use? This sounds really strange and complex if I have to
support various components in the list. What is the best way to render different UIComponents
for each column in this case? Is it possible to add the components in the backing
bean and process them within <t:columns> ? My code snippets: <t:dataTable id="items"
value="#{AnnoControllerBean.documents}" var="document"> <t:columns
id="columns" value="#{AnnoControllerBean.columnHeaders}"
var="columnHeader" >
<h:outputText value="#{AnnoControllerBean.columnValue}" /> </t:columns> </t:dataTable> class MyController { private DataModel documentModel; private DataModel columnHeaders; public AnnotationController() { List<String>
headerList = new ArrayList<String> (); headerList.add("Selected"); headerList.add("No"); headerList.add("Title");
headerList.add("Name"); columnHeaders
= new ListDataModel(headerList); List
rowList = new ArrayList(); List documents
= delegate.getDocuments(); Iterator
iter= documents.iterator();
while(iter.hasNext() ) {
Document document = (Document) iter.next();
List colList = new ArrayList(); colList.add(document.getSelected()); colList.add(document.getDocumentId());
colList.add(document.getDatafield().get(("title")));
colList.add(document.getDatafield().get(("name")));
rowList.add(colList); }
documentModel = new ListDataModel(rowList); } public DataModel getDocuments() { return
documentModel; } public DataModel
getColumnHeaders(){ return
columnHeaders; } public Object getColumnValue(){ Object
columnValue = null; if(documentModel.isRowAvailable()
&& columnHeaders.isRowAvailable()) { List
list = (List)documentModel.getRowData(); columnValue
= list.get(columnHeaders.getRowIndex()); } return
columnValue; } ... Thanks for any help. |
- dynamic columns with different UI components Michael Heinen
- Re: dynamic columns with different UI components Mathias Brökelmann
