You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by kevin_zhai <ja...@gmail.com> on 2006/11/01 00:43:41 UTC

Re: How to dynamically show different components for each row in a table

Hi 
    If we can create table in back bean dynamically,
maybe it can attach me the requirement,
can  anybody give me advice,thanks


Simon Kitching-3 wrote:
> 
> Hi Kevin,
> 
> kevin_zhai wrote:
>> I have a  Table that has a column containing buttons for operations on
>> each
>> row. Each row may have different operations applicable to it, so the
>> buttons
>> for each row need to be determined dynamically based on the contents of
>> row. 
>>
>> I have seen code to dynamically create buttons, but what I would like to
>> know is how to do this on a per-row basis, so that row 1 would might have
>> 1
>> button, row 2 would have 3 buttons and so on. I would like to avoid the
>> solution of creating all of the possible types of buttons and hiding the
>> ones that do not apply to the current row.
>>   
> 
> It is not possible to change the set of components per-row. Instead, you 
> *must* define all the possible types of components present in a row, 
> then use the rendered attribute to show/hide them based on what you want 
> to display on a specific row.
> 
> See the javadoc for the UIData component for details:
>   http://myfaces.apache.org/api/apidocs/index.html
> 
> Regards,
> 
> Simon
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7105388
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Jeff Bischoff <jb...@klkurz.com>.
And here's the link [1] to the picture he was talking about. He put it 
all the way at the bottom (below the quotes), so we missed it.

[1] http://www.nabble.com/file/3932/pro.jpg



Re: How to dynamically show different components for each row in a table

Posted by Jeff Bischoff <jb...@klkurz.com>.
Yes Kevin, you can dynamically build a component tree if that is what 
you need to do. If you use dataTable specifically though, you will need 
to do the "rendered" trick.

I have never needed to manually build my own component tree, but there 
have been several threads on this in the past. Please search the 
archives [1].

[1] http://www.nabble.com/MyFaces---Users-f181.html

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

kevin_zhai wrote:
> HI Jeff :
>           My requiremet is to be able show different components for each row
> in a table,
> If use your way,can do logic judge(I need select component depend on
> database data)?
> I know jstl can't use in jsf page, isn't it ?
> 
>   



Re: How to dynamically show different components for each row in a table

Posted by kevin_zhai <ja...@gmail.com>.
HI Jeff :
          My requiremet is to be able show different components for each row
in a table,
If use your way,can do logic judge(I need select component depend on
database data)?
I know jstl can't use in jsf page, isn't it ?

  
-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7117380
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Jeff Bischoff <jb...@klkurz.com>.
Kevin,

I don't understand why you want to use t:dataTable. If you chose 
dataTable, you will have to define all the possible components on every 
row like Simon said. You said you don't want that. So you have to use 
something else, like h:panelGrid. Heck, you could even use whatever 
logic you have in your legacy program and output raw html surround by 
f:verbatims.

e.g.

<f:verbatim>
<table>
   <tr>
     <td></f:verbatim><h:inputText.../><f:verbatim></td>
   </tr>
   ...
</table>
</f:verbatim>

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

kevin_zhai wrote:
> Hi Jeff
>        Thanks your response,I just want use <t:dataTable> to implement
>  <http://www.nabble.com/file/3932/pro.jpg > and the html code just like
> this:
> <table> 
>  <tr> 
>    <td class="SCS_Value_c"> 
>    <input type=text name="num" size=5 class="input_text_df" disabled> ULD 
>    </td> 
>    . 
>    . 
>  </tr> 
>  <tr> 
>     <td class="SCS_Value_c"> 
>         <input type=radio name="o1" disabled> UCR2U<BR> 
>         <input type=radio name="o1" disabled> UCR2K 
>     </td> 
>     . 
>     . 
>  </tr> 
> 
> <tr> 
>    <td class="SCS_Value_c"> 
>    <input type=text name="num"> 
>    </td> 
>    . 
>    . 
>  </tr> 
> 
>  <tr> 
>    <td class="SCS_Value_c"> 
>    <input type=checkBox name="num"> 
>    </td> 
>    . 
>    . 
>  </tr> 
>  <tr> 
>  ....... 
>  </tr> 
>  . 
>  . 
> </table> 
> 
>     Do you understand me?
> 
> 
> best regards



Re: How to dynamically show different components for each row in a table

Posted by kevin_zhai <ja...@gmail.com>.
Hi Simon:
           I use javascript to control the component render,,
----------------
----------------
<t:column>
				<f:facet name="header">
					<h:outputText
						value="#{ChangeOperationGeneralListFormBean.newValueLabel}"
						styleClass="SCS_Value_c" />
				</f:facet>
				
				<t:div id="column1" forceId="true" />
				
				<t:inputHidden value="#{rowvar.active}" id="new" forceId="true" />
				<t:inputHidden value="#{rowvar.type}" id="type" forceId="true" />
				<t:inputHidden value="#{rowvar.unit}" id="unit" forceId="true" />
			

			</t:column>
----------------

the javascript is:

function init() {
  //alert("helo");
  var x=0;
  var typeId;
  var unitId;
  var newValueId;
  var columnId;
  var CONCOLUMN;
  do{
    CONCOLUMN="column1["+x+"]";
    columnId=document.getElementById(CONCOLUMN);
    typeId=document.getElementById("type["+x+"]");
    unitId=document.getElementById("unit["+x+"]");
    newValueId=document.getElementById("new["+x+"]");
    if(typeId==null)
    {
     break;
    }
    if(typeId.getAttribute("value")=="text")
    {
     
    //columnId.outerHTML="<input type='text' id="+columnId+"
value="+newValueId.getAttribute("value")+" //disabled='disabled'>";
   //  columnId.outerHTML="<input type='text' name="+CONCOLUMN+"
id="+CONCOLUMN+" //value="+newValueId.getAttribute("value")+"
disabled='disabled'>"+unitId.getAttribute("value");
     columnId.innerHTML="<input type='text'  id="+CONCOLUMN+"
value="+newValueId.getAttribute("value")+">";
    }else if(typeId.getAttribute("value")=="radio")
    {
      var str=unitId.getAttribute("value").split("|");  
      columnId.innerHTML="<input type='radio' name="+CONCOLUMN+"
id="+CONCOLUMN+" value="+str[0]+">"+str[0]+"<br>"+
      "<input type='radio' name="+CONCOLUMN+" id="+CONCOLUMN+"
value="+str[1]+" checked='checked' >"+str[1];
    }else if(typeId.getAttribute("value")=="checkBox")
    {
       columnId.innerHTML="<input type='Checkbox' name="+CONCOLUMN+"
id="+CONCOLUMN+" value="+newValueId.getAttribute("value")+"
>"+unitId.getAttribute("value");
    }
      
    x++;
  }while(1);
}

My ideality is use purely jsf to implements..
The second column(ie."new" column) may have four different
component(Textbox,Radio,button,Checkbox)
Thanks everybody reply,
I think you can give me further advice..thanks thanks thanks
-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7125615
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Simon Kitching <si...@rhe.co.nz>.
kevin_zhai wrote:
> Hi Jeff
>        Thanks your response,I just want use <t:dataTable> to implement
>  <http://www.nabble.com/file/3932/pro.jpg > 
Ah, I see.

I think what you want is a table where:

column 1 contains a checkbox component.

column 2 contains two components:
   * a panelGroup containing a text input and a label
   * a t:dataList  (or possibly an h:dataTable)
where only one of these has rendered=true

column 3 contains a text output

etc.

The dataList component incolumn 2 can then render any number of radio 
buttons.

Note that what radio buttons are rendered depends on the data model of 
the nested t:dataList or h:dataTable. They are not direct children of 
the main table, so its list of direct children is fixed.


Regards,

Simon

Re: How to dynamically show different components for each row in a table

Posted by kevin_zhai <ja...@gmail.com>.
Hi Jeff
       Thanks your response,I just want use <t:dataTable> to implement
 <http://www.nabble.com/file/3932/pro.jpg > and the html code just like
this:
<table> 
 <tr> 
   <td class="SCS_Value_c"> 
   <input type=text name="num" size=5 class="input_text_df" disabled> ULD 
   </td> 
   . 
   . 
 </tr> 
 <tr> 
    <td class="SCS_Value_c"> 
        <input type=radio name="o1" disabled> UCR2U<BR> 
        <input type=radio name="o1" disabled> UCR2K 
    </td> 
    . 
    . 
 </tr> 

<tr> 
   <td class="SCS_Value_c"> 
   <input type=text name="num"> 
   </td> 
   . 
   . 
 </tr> 

 <tr> 
   <td class="SCS_Value_c"> 
   <input type=checkBox name="num"> 
   </td> 
   . 
   . 
 </tr> 
 <tr> 
 ....... 
 </tr> 
 . 
 . 
</table> 

    Do you understand me?


best regards
-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7116310
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Jeff Bischoff <jb...@klkurz.com>.
Ooh... he's not talking about dataTables... he's talking about html tables.

Kevin, I'd suggest you get a book on JSF, to get you started.

What you want here is an h:panelGrid (for the table), an 
h:panelGroup(for each row), and for the input components... h:inputText, 
h:selectOneRadio, and h:selectBooleanCheckbox.

e.g.

<h:panelGrid>
    <h:panelGroup>
       <h:inputText .../>
    </h:panelGroup>
    <h:panelGroup>
       <h:selectOneRadio>
          <f:selectItems .../>
       </h:selectOneRadio>
    </h:panelGroup>
    ...
</h:panelGrid>

Don't use h:dataTable unless you are displaying some kind of data 
collection.

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

kevin_zhai wrote:
> Hi Simon:
>        It's not img,the html code just like this:
> ========
>   <table>
>  <tr>
>    <td class="SCS_Value_c">
>    <input type=text name="num" size=5 class="input_text_df"
> disabled>&nbsp;ULD
>    </td>
>    .
>    .
>  </tr>
>  <tr>
>     <td class="SCS_Value_c">
>         <input type=radio name="o1" disabled>&nbsp;UCR2U<BR>
>         <input type=radio name="o1" disabled>&nbsp;UCR2K
>     </td>
>     .
>     .
>  </tr>
> 
> <tr>
>    <td class="SCS_Value_c">
>    <input type=text name="num">
>    </td>
>    .
>    .
>  </tr>
> 
>  <tr>
>    <td class="SCS_Value_c">
>    <input type=checkBox name="num">
>    </td>
>    .
>    .
>  </tr>
>  <tr>
>  .......
>  </tr>
>  .
>  .
> </table>
> ========
> 
> the picture just show,what's I need  to implement table,
> how can I implement use jsf?,I don't know.
> 
> 
> best regards
> 



Re: How to dynamically show different components for each row in a table

Posted by kevin_zhai <ja...@gmail.com>.
Hi Simon:
       It's not img,the html code just like this:
========
  <table>
 <tr>
   <td class="SCS_Value_c">
   <input type=text name="num" size=5 class="input_text_df"
disabled>&nbsp;ULD
   </td>
   .
   .
 </tr>
 <tr>
    <td class="SCS_Value_c">
        <input type=radio name="o1" disabled>&nbsp;UCR2U<BR>
        <input type=radio name="o1" disabled>&nbsp;UCR2K
    </td>
    .
    .
 </tr>

<tr>
   <td class="SCS_Value_c">
   <input type=text name="num">
   </td>
   .
   .
 </tr>

 <tr>
   <td class="SCS_Value_c">
   <input type=checkBox name="num">
   </td>
   .
   .
 </tr>
 <tr>
 .......
 </tr>
 .
 .
</table>
========

the picture just show,what's I need  to implement table,
how can I implement use jsf?,I don't know.


best regards

-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7108351
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Simon Kitching <si...@rhe.co.nz>.
kevin_zhai wrote:
> Hi Simon:
>        thank you give me advises,I expert you give me more advise about--
> how to implement pro.jpg show content?
> The 'new'column show different components in per row,if I use rendered
> attribute how can control
>  every row different(the  picture show)
>   


What exactly are you trying to do?

If I understand your description above, you want to generate a table:
  <table>
  <tr><td><img .../></td></tr>
  <tr><td><img .../></td></tr>
  <tr><td><img .../></td></tr>
  </table>
where the img tag points to a different image.

Have I understood right?

Regards,

Simon



Re: How to dynamically show different components for each row in a table

Posted by kevin_zhai <ja...@gmail.com>.
Hi Simon:
       thank you give me advises,I expert you give me more advise about--
how to implement pro.jpg show content?
The 'new'column show different components in per row,if I use rendered
attribute how can control
 every row different(the  picture show)

best regards
        kevin



Simon Kitching-3 wrote:
> 
> That article isn't describing how to create a table with different 
> components in each row; it simply describes how to use java code to 
> define a table that has the *same* components in each row. With this 
> approach, it is possible to vary the number of columns present in the 
> table each time the page is re-rendered. However you cannot have 
> different components in different rows of the table.
> 
> MyFaces should work fine with this example code.
> 
> To solve your original problem, you should simply use the approach you 
> described in your first posting - define all the components that can 
> possibly exist in the row, then set the rendered attribute to false for 
> ones that you don't want visible in a specific row.
> 
> kevin_zhai wrote:
>> Hi simon:
>>
>>    I find a url desc how to implement,but it's sun's
>> tool(jscreator),myfaces
>> it's real can't do that...
>>   
>> http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/createTableDynamically.html 
>>
>>
>> Simon Kitching-3 wrote:
>>   
>>> The UIData component uses the "flyweight" pattern to process its rows, 
>>> as described in the javadoc I pointed out. Because of this, I'm pretty 
>>> sure that attempting to change the child components of a UIData object 
>>> while it is iterating over its rows will have most unpleasant
>>> side-effects.
>>>
>>> Regards,
>>>
>>> Simon
>>>
>>> kevin_zhai wrote:
>>>     
>>>> Hi 
>>>>     If we can create table in back bean dynamically,
>>>> maybe it can attach me the requirement,
>>>> can  anybody give me advice,thanks
>>>>
>>>>
>>>> Simon Kitching-3 wrote:
>>>>   
>>>>       
>>>>> Hi Kevin,
>>>>>
>>>>> kevin_zhai wrote:
>>>>>     
>>>>>         
>>>>>> I have a  Table that has a column containing buttons for operations
>>>>>> on
>>>>>> each
>>>>>> row. Each row may have different operations applicable to it, so the
>>>>>> buttons
>>>>>> for each row need to be determined dynamically based on the contents
>>>>>> of
>>>>>> row. 
>>>>>>
>>>>>> I have seen code to dynamically create buttons, but what I would like
>>>>>> to
>>>>>> know is how to do this on a per-row basis, so that row 1 would might
>>>>>> have
>>>>>> 1
>>>>>> button, row 2 would have 3 buttons and so on. I would like to avoid
>>>>>> the
>>>>>> solution of creating all of the possible types of buttons and hiding
>>>>>> the
>>>>>> ones that do not apply to the current row.
>>>>>>   
>>>>>>       
>>>>>>           
>>>>> It is not possible to change the set of components per-row. Instead,
>>>>> you 
>>>>> *must* define all the possible types of components present in a row, 
>>>>> then use the rendered attribute to show/hide them based on what you
>>>>> want 
>>>>> to display on a specific row.
>>>>>
>>>>> See the javadoc for the UIData component for details:
>>>>>   http://myfaces.apache.org/api/apidocs/index.html
>>>>>
>>>>> Regards,
>>>>>
>>>>> Simon
>>>>>
>>>>>
>>>>>
>>>>>     
>>>>>         
>>>>   
>>>>       
>>>
>>>     
>>
>>   
> 
> 
> 
http://www.nabble.com/file/3932/pro.jpg 
-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7107505
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Simon Kitching <si...@rhe.co.nz>.
That article isn't describing how to create a table with different 
components in each row; it simply describes how to use java code to 
define a table that has the *same* components in each row. With this 
approach, it is possible to vary the number of columns present in the 
table each time the page is re-rendered. However you cannot have 
different components in different rows of the table.

MyFaces should work fine with this example code.

To solve your original problem, you should simply use the approach you 
described in your first posting - define all the components that can 
possibly exist in the row, then set the rendered attribute to false for 
ones that you don't want visible in a specific row.

kevin_zhai wrote:
> Hi simon:
>
>    I find a url desc how to implement,but it's sun's tool(jscreator),myfaces
> it's real can't do that...
>   
> http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/createTableDynamically.html 
>
>
> Simon Kitching-3 wrote:
>   
>> The UIData component uses the "flyweight" pattern to process its rows, 
>> as described in the javadoc I pointed out. Because of this, I'm pretty 
>> sure that attempting to change the child components of a UIData object 
>> while it is iterating over its rows will have most unpleasant
>> side-effects.
>>
>> Regards,
>>
>> Simon
>>
>> kevin_zhai wrote:
>>     
>>> Hi 
>>>     If we can create table in back bean dynamically,
>>> maybe it can attach me the requirement,
>>> can  anybody give me advice,thanks
>>>
>>>
>>> Simon Kitching-3 wrote:
>>>   
>>>       
>>>> Hi Kevin,
>>>>
>>>> kevin_zhai wrote:
>>>>     
>>>>         
>>>>> I have a  Table that has a column containing buttons for operations on
>>>>> each
>>>>> row. Each row may have different operations applicable to it, so the
>>>>> buttons
>>>>> for each row need to be determined dynamically based on the contents of
>>>>> row. 
>>>>>
>>>>> I have seen code to dynamically create buttons, but what I would like
>>>>> to
>>>>> know is how to do this on a per-row basis, so that row 1 would might
>>>>> have
>>>>> 1
>>>>> button, row 2 would have 3 buttons and so on. I would like to avoid the
>>>>> solution of creating all of the possible types of buttons and hiding
>>>>> the
>>>>> ones that do not apply to the current row.
>>>>>   
>>>>>       
>>>>>           
>>>> It is not possible to change the set of components per-row. Instead, you 
>>>> *must* define all the possible types of components present in a row, 
>>>> then use the rendered attribute to show/hide them based on what you want 
>>>> to display on a specific row.
>>>>
>>>> See the javadoc for the UIData component for details:
>>>>   http://myfaces.apache.org/api/apidocs/index.html
>>>>
>>>> Regards,
>>>>
>>>> Simon
>>>>
>>>>
>>>>
>>>>     
>>>>         
>>>   
>>>       
>>
>>     
>
>   


Re: How to dynamically show different components for each row in a table

Posted by kevin_zhai <ja...@gmail.com>.
Hi simon:

   I find a url desc how to implement,but it's sun's tool(jscreator),myfaces
it's real can't do that...
  
http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/createTableDynamically.html 


Simon Kitching-3 wrote:
> 
> The UIData component uses the "flyweight" pattern to process its rows, 
> as described in the javadoc I pointed out. Because of this, I'm pretty 
> sure that attempting to change the child components of a UIData object 
> while it is iterating over its rows will have most unpleasant
> side-effects.
> 
> Regards,
> 
> Simon
> 
> kevin_zhai wrote:
>> Hi 
>>     If we can create table in back bean dynamically,
>> maybe it can attach me the requirement,
>> can  anybody give me advice,thanks
>>
>>
>> Simon Kitching-3 wrote:
>>   
>>> Hi Kevin,
>>>
>>> kevin_zhai wrote:
>>>     
>>>> I have a  Table that has a column containing buttons for operations on
>>>> each
>>>> row. Each row may have different operations applicable to it, so the
>>>> buttons
>>>> for each row need to be determined dynamically based on the contents of
>>>> row. 
>>>>
>>>> I have seen code to dynamically create buttons, but what I would like
>>>> to
>>>> know is how to do this on a per-row basis, so that row 1 would might
>>>> have
>>>> 1
>>>> button, row 2 would have 3 buttons and so on. I would like to avoid the
>>>> solution of creating all of the possible types of buttons and hiding
>>>> the
>>>> ones that do not apply to the current row.
>>>>   
>>>>       
>>> It is not possible to change the set of components per-row. Instead, you 
>>> *must* define all the possible types of components present in a row, 
>>> then use the rendered attribute to show/hide them based on what you want 
>>> to display on a specific row.
>>>
>>> See the javadoc for the UIData component for details:
>>>   http://myfaces.apache.org/api/apidocs/index.html
>>>
>>> Regards,
>>>
>>> Simon
>>>
>>>
>>>
>>>     
>>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-dynamically-show-different-components-for-each-row-in-a-table-tf2548765.html#a7106600
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: How to dynamically show different components for each row in a table

Posted by Simon Kitching <si...@rhe.co.nz>.
The UIData component uses the "flyweight" pattern to process its rows, 
as described in the javadoc I pointed out. Because of this, I'm pretty 
sure that attempting to change the child components of a UIData object 
while it is iterating over its rows will have most unpleasant side-effects.

Regards,

Simon

kevin_zhai wrote:
> Hi 
>     If we can create table in back bean dynamically,
> maybe it can attach me the requirement,
> can  anybody give me advice,thanks
>
>
> Simon Kitching-3 wrote:
>   
>> Hi Kevin,
>>
>> kevin_zhai wrote:
>>     
>>> I have a  Table that has a column containing buttons for operations on
>>> each
>>> row. Each row may have different operations applicable to it, so the
>>> buttons
>>> for each row need to be determined dynamically based on the contents of
>>> row. 
>>>
>>> I have seen code to dynamically create buttons, but what I would like to
>>> know is how to do this on a per-row basis, so that row 1 would might have
>>> 1
>>> button, row 2 would have 3 buttons and so on. I would like to avoid the
>>> solution of creating all of the possible types of buttons and hiding the
>>> ones that do not apply to the current row.
>>>   
>>>       
>> It is not possible to change the set of components per-row. Instead, you 
>> *must* define all the possible types of components present in a row, 
>> then use the rendered attribute to show/hide them based on what you want 
>> to display on a specific row.
>>
>> See the javadoc for the UIData component for details:
>>   http://myfaces.apache.org/api/apidocs/index.html
>>
>> Regards,
>>
>> Simon
>>
>>
>>
>>     
>
>