Hi Experts,
Here's my requirment....
I'have to display listing of questions and associated answers in the variety of different UIComponents.
These questions and the control type(UIComponent) are not known at the compile time,so i cant create them on the jsp page.
Questions and its associated control type(UIComponent) ,for the answers,are know at the run-time.
So i have to dynamically generate these UIComponent in the <h:datatable or rather to say in other words i've to dynamically create this datatable.
Here's my jsp
--------------------
<f:view>
<h:form id="form1">
<h:commandButton value="Create Controls" id="commandButton1" type="submit" action="#{dynamicQuestions.createQuestionControlAction}" />
<h:dataTable binding="#{dynamicQuestions.dataTable}" value="#{requirementBean.questionList}"
var="questions" border="1" id="RootTable" />
</h:form>
</f:view>
-------------------
The java method
Application application = FacesContext.getCurrentInstance().getApplication();
UIViewRoot uiViewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlDataTable dataTable = (HtmlDataTable) application.createComponent(HtmlDataTable.COMPONENT_TYPE);
dataTable.setVar("questions");
//dataTable.setValueBinding("binding", (ValueBinding) application.createValueBinding("#{dynamicQuestions.dataTable}"));
dataTable.setValueBinding("value", (ValueBinding) application.createValueBinding("#{requirementBean.questionList}"));
dataTable.setId("test_table");
String vbStr = "#{questions.questionData}";
ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlOutputText output = new HtmlOutputText();
output.setId("HtmlOutputText1");
output.setValueBinding("value", vb);
vbStr = "#{questions.itemList}";
vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlSelectOneMenu hsom = new HtmlSelectOneMenu();
hsom.setId("HtmlSelectOneMenu2");
hsom.setValueBinding("value",vb);
vbStr = "#{questions.itemList}";
vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlSelectManyListbox hsmlb = new HtmlSelectManyListbox();
hsmlb.setId("HtmlSelectManyListbox3");
hsmlb.setValueBinding("value",vb);
HtmlSelectBooleanCheckbox chb=new HtmlSelectBooleanCheckbox();
chb.setId("HtmlSelectBooleanCheckbox4");
chb.setValueBinding("value", vb);
//datatable column
UIColumn column = new UIColumn();
column.setId("UIColumn4");
column.getChildren().add(output);
column.getChildren().add(hsom);
column.getChildren().add(hsmlb);
HtmlOutputText headerComponent = new HtmlOutputText();
headerComponent.setId("HtmlOutputTextHeader5");
column.setHeader(headerComponent);
headerComponent.setValue("columnName= 3");
dataTable.getChildren().add(column);
uiViewRoot.findComponent("form1").getChildren().add(dataTable);
UIViewRoot uiViewRoot = FacesContext.getCurrentInstance().getViewRoot();
HtmlDataTable dataTable = (HtmlDataTable) application.createComponent(HtmlDataTable.COMPONENT_TYPE);
dataTable.setVar("questions");
//dataTable.setValueBinding("binding", (ValueBinding) application.createValueBinding("#{dynamicQuestions.dataTable}"));
dataTable.setValueBinding("value", (ValueBinding) application.createValueBinding("#{requirementBean.questionList}"));
dataTable.setId("test_table");
String vbStr = "#{questions.questionData}";
ValueBinding vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlOutputText output = new HtmlOutputText();
output.setId("HtmlOutputText1");
output.setValueBinding("value", vb);
vbStr = "#{questions.itemList}";
vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlSelectOneMenu hsom = new HtmlSelectOneMenu();
hsom.setId("HtmlSelectOneMenu2");
hsom.setValueBinding("value",vb);
vbStr = "#{questions.itemList}";
vb = FacesContext.getCurrentInstance().getApplication().createValueBinding(vbStr);
HtmlSelectManyListbox hsmlb = new HtmlSelectManyListbox();
hsmlb.setId("HtmlSelectManyListbox3");
hsmlb.setValueBinding("value",vb);
HtmlSelectBooleanCheckbox chb=new HtmlSelectBooleanCheckbox();
chb.setId("HtmlSelectBooleanCheckbox4");
chb.setValueBinding("value", vb);
//datatable column
UIColumn column = new UIColumn();
column.setId("UIColumn4");
column.getChildren().add(output);
column.getChildren().add(hsom);
column.getChildren().add(hsmlb);
HtmlOutputText headerComponent = new HtmlOutputText();
headerComponent.setId("HtmlOutputTextHeader5");
column.setHeader(headerComponent);
headerComponent.setValue("columnName= 3");
dataTable.getChildren().add(column);
uiViewRoot.findComponent("form1").getChildren().add(dataTable);
Right now im trying to only create these UIComponents , just for testing purpose..
HtmlSelectManyListbox ,HtmlSelectOneMenu,HtmlOutputText
But when i pressed the CreateControls button nothing happens i.e there is no output.
Please guide me as to where im going wrong and what is the correct way of creating a dynamic datatable.
Waiting for the experts reply...
Thanks
Ved
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

