You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by James Ellis <el...@hotmail.com> on 2006/05/02 00:38:35 UTC
Dynamically Set Column Values In Datatable
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). 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)?