This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

Creating Datatable dynamically

Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My requirment is that i have to create a dynamic datatable and which contains listing of Questions and its respectives Answer. These questions and answer come from the server and along with the answer i also get the answer type , which tells what is the type of the UIComponent that is associated with the answer say input text,select many,select one etc., so i have to dynamically create these UIComponent inside the datable based on the answer type.
Actually i'm having the logic to create the components which is based on the answer type which comes from the backend and this answer type define what kind type of component(component for single answers/component for multiple answer,input and other types) needs to be created.(this will be done in the if-else block)

My problem is that im not able to create this componets dynamically in the data table.
In the code below , i have binded the datatable and in the java method i 'm trying to create the ui components(as of now im creating it without the creation logic of answer type).
The idea was to just try and see whether the components are created and is getting added to the datable.

when i run this code im getting no output.

Please suggest me where im going wrong and what is the correct approach.

I'm really in a dire straits.

Here's the code:



<h:dataTable id="mainTable" binding="#{dynamicQuestions.dataTable}" value="#{requirementBean.questionList}"

var="questions" border="1"/>

Java method


public UIData getDataTable()


Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot uiViewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlDataTable dataTable =(HtmlDataTable)uiViewRoot.findComponent("mainTable");

//------------------- adding HtmlOutputText ---------------//
String vbStr = "#{questions.questionData}";
ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlOutputText output = new HtmlOutputText();
output.setValueBinding("value", vb);

//------------------- adding HtmlSelectOneMenu ---------------//
vbStr = "#{questions.itemList}";
vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);

HtmlSelectOneMenu hsom = new HtmlSelectOneMenu();

//------------------- adding HtmlSelectManyListbox ---------------//

vbStr = "#{questions.itemList}";
vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);

HtmlSelectManyListbox hsmlb = new HtmlSelectManyListbox();

//datatable column
UIColumn column = new UIColumn();


return dataTable;



Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSF has a complex lifecycle. It all boils down to if you have considered the JSF life cycle in the code that you pasted.

To me it appears that the <h:datable> is rendered before calling your method.

I think you need to use IBM's scriptcollector
<h:ScriptCollector pre-Render ="onPageLoadBegin()">

and put all the pre render logic in onPageLoadBegin(facesContext)

Hope this helps.

Ravisekhar Kopparthi
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic