This looks like a very bad idea to me. If there are a limited number of answer component-types (from a quick glance at your code I see htmlSelectMany, One, Boolean) why not just have all those component types and control whether or not they are shown with the “rendered” attribute. Afaic this is the preferred way to dynamically render components.

 

Example in psuedo JSF:

 

<h:dataTable var=”questionAnswerPair” value=”#{qaBean.questionAnswerPairs}”>

   <h:column>

       <%-- Question logic --%>

   </h:column>

   <h:column>

       <component1 … rendered=”#{questionAnswerPair.isRenderComponentType1}”/>

       <component2 … rendered=”#{questionAnswerPair.isRenderComponentType2}”/>

       <component3 … rendered=”#{questionAnswerPair.isRenderComponentType3}”/>

    </h:column>

<h:dataTable>

 


From: ved.gunjan [mailto:[EMAIL PROTECTED]
Sent: Thursday, 13 July 2006 7:36 AM
To: [EMAIL PROTECTED]; users@myfaces.apache.org
Subject: Creating Dynamic h:datatable

 

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);
       

 

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

This correspondence is for the named persons only.
It may contain confidential or privileged information or both.
No confidentiality or privilege is waived or lost by any mis transmission.
If you receive this correspondence in error please delete it from your system immediately and notify the sender.
You must not disclose, copy or relay on any part of this correspondence, if you are not the intended recipient.
Any opinions expressed in this message are those of the individual sender except where the sender expressly,
and with the authority, states them to be the opinions of the Department of Emergency Services, Queensland.

Reply via email to