All the UIInput components should be placed in the column and they should be rendered upon some value. Rendered solution like the julian's, would be practical.

On 5/2/06, Julian Ray <[EMAIL PROTECTED]> wrote:
We have a similar issue where we create an HTML form on the fly with a
number of pre-defined response types such as input a number 0-n, input a
number 1-n, yes/no, yes/no/na etc. We do this by including a input controls
iwthin the column and using a rendered="#{...}" from the backing bean to
tell tell the form which control to render for a particular question.  The
JSp looks like:



                           <t:dataTable renderedIfEmpty="false"
cellpadding="2" cellspacing="1"
                                columnClasses="centerAlignCol, leftAlignCol,
inputCol"
                                headerClass="list-header" id="dataTable1"
rowClasses="list-row-even,list-row-odd" styleClass="dataTable"
                                value="#{NewForm.questions}"
var="currentRow" width="100%">
                               <h:column>
                                   <h:outputText
value="#{currentRow['index'] + 1}"/>
                                    <f:facet name="header">
                                        <h:outputText value="Question"/>
                                    </f:facet>
                               </h:column>
                               <h:column>
                                   <h:outputText
value="#{currentRow.bean['prompt']}" escape="false"/>
                                    <f:facet name="header">
                                        <h:outputText value=""
escape="false"/>
                                    </f:facet>
                               </h:column>
                                <h:column>
                                    <cms:spinner id="ipt1" mode="client"
styleClass="spinner" minimum="1" maximum="999" size="3"
value="#{currentRow['value']}" rendered="#{NewForm.renderOneOrMore }"/>

                                    <cms:spinner id="ipt2" mode="client"
styleClass="spinner" minimum="0" maximum="999" size="3"
value="#{currentRow['value']}" rendered="#{NewForm.renderZeroOrMore }"/>

                                        <h:selectOneRadio id="ipt3"
layout="lineDirection" required="true" value="#{currentRow['value']}"
rendered="#{NewForm.renderYesNoNA}">
                                            <f:selectItems
value="#{NewForm.selectionYesNoNA}"/>
                                        </h:selectOneRadio>

                                        <h:selectOneRadio id="ipt4"
layout="lineDirection" required="true" value="#{currentRow['value']}"
rendered="#{NewForm.renderYesNo}">
                                            <f:selectItems
value="#{NewForfm.selectionYesNo}"/>
                                        </h:selectOneRadio>
                                        <h:message for="">errorClass="errorMessage"/>
                                        <h:message for="">errorClass="errorMessage"/>
                                        <h:message for="">errorClass="errorMessage"/>
                                        <h:message for="">errorClass="errorMessage"/>
                                    <f:facet name="header">
                                        <h:outputText value=""
escape="false"/>
                                    </f:facet>
                                </h:column>

-----Original Message-----
From: James Ellis [mailto: [EMAIL PROTECTED]]
Sent: Tuesday, May 02, 2006 9:32 AM
To: [email protected]
Subject: Re: Add Row With Component To Datatable

But I don't know if the form element will be a textbox or a dropdown...so I
can't hardcode them into the page like that.  I would think I'd need to add
them to the datatable through the backend only I can't seem to figure out
how to add a row (only a column).  Does anyone know how I can specify
(through the backend) that the datatable will have something like this:

Column 1                    Column 2
<text blah blah>         <textbox>
<more text>              <dropdown>
<again more text>      <textarea>
<text keeps going>     <textbox>
<text blah blah>         <radio box>


Again to sum up....a user selects from a dropdown which will fire a
ValueChangeListener which will determine which fields are displayed.  I
can't hardcode the fields since I don't know what they'll be until the user
selects from the drop down box.


>From: "Mert Çalýþkan" <[EMAIL PROTECTED]>
>Reply-To: "MyFaces Discussion" < [email protected]>
>To: "MyFaces Discussion" <[email protected]>
>Subject: Re: Add Row With Component To Datatable
>Date: Tue, 2 May 2006 13:07:03 +0300
>
>just put UIInput components whereever you want them.
>
>For example,
>    instead of
>        <h:outputText value="#{rowVar.radical_value}"/>,
>    use
>        <h:inputText id="text4" value="#{ rowVar.radical_value}" /> If
>templatesCollection is a session-managed bean there would be no problem
>for inputting values.
>
>Regards,
>
>Mert.
>
>
>On 5/2/06, James Ellis < [EMAIL PROTECTED]> wrote:
>>
>>I want to have a datatable with two columns.  The first column will
>>always be text, but the second column will have some sort of form
>>element (textbox, textarea, dropdown box etc) populated dynamically.
>>How do I populate the datatable dynamically?
>>
>>I tried the code below but all I got was the name of the class of the
>>form element (since it's toString method must have been called):
>>
>>(from JSF page)
>>
>><h:dataTable id="dynSourceTable" columnClasses="label" headerClass="label"
>>value="#{dynSourceTemplateBean.templatesCollection}" var="rowVar"
>>border="0">
>>        <h:column>
>>
>>        <f:facet name="header">
>>                <f:verbatim>Left Hand Header</f:verbatim>
>>        </f:facet>
>>
>>        <h:outputText value="#{rowVar.radical_name}"/>
>>        </h:column>
>>
>>
>>        <h:column>
>>
>>        <f:facet name="header">
>>                <f:verbatim>Right Hand Header</f:verbatim>
>>        </f:facet>
>>
>>        <h:outputText value="#{rowVar.radical_value}"/>
>>
>>        </h:column>
>>
>></h:dataTable>
>>
>>
>>(from backing bean)
>>
>>private ArrayList templatesCollection = null;
>>
>>public ArrayList getTemplatesCollection() {
>>        System.out.println("Inside getTemplatesCollection");
>>        ArrayList tc = new ArrayList();
>>        HashMap hm1 = new HashMap();
>>        hm1.put(new String("radical_name"), new String("radical name1
>>"));
>>
>>        UIInput image_url = new UIInput();
>>        image_url.setValue("textbox value display text");
>>
>>        hm1.put(new String("radical_value"), image_url);
>>
>>
>>        HashMap hm2 = new HashMap();
>>        hm2.put(new String("radical_name"), new String("radical name2
>> "));
>>
>>        UIInput image_url2 = new UIInput();
>>        image_url2.setValue("textbox2 value display text222");
>>
>>        hm2.put(new String("radical_value"), image_url2);
>>        tc.add(hm1);
>>         tc.add(hm2);
>>        return tc;
>>}
>>
>>
>>
>>Does anyone know how I could dynamically set the rows in the datatable
>>with form elements (not just text)?
>>
>>
>>



Reply via email to