You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Michael Heinen <mh...@recommind.com> on 2006/01/30 15:45:27 UTC

dynamic columns with different UI components

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.


Re: dynamic columns with different UI components

Posted by Mathias Brökelmann <mb...@googlemail.com>.
Hi,

its better to post such messages to the user list.

You should use a complex object for your columns. This allows you to
use boolean is* methods to determine which type of column should be
rendered. That is much easier than binding t:columns into a backing
bean to create depended components.

2006/1/30, Michael Heinen <mh...@recommind.com>:
>
>
>
> 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.


--
Mathias

Re: dynamic columns with different UI components

Posted by Mathias Brökelmann <mb...@googlemail.com>.
Hi,

its better to post such messages to the user list.

You should use a complex object for your columns. This allows you to
use boolean is* methods to determine which type of column should be
rendered. That is much easier than binding t:columns into a backing
bean to create depended components.

2006/1/30, Michael Heinen <mh...@recommind.com>:
>
>
>
> 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.


--
Mathias