0 Replies Latest reply on Jun 9, 2010 12:33 AM by Gen Sys

    Creating components dynamically

    Gen Sys Newbie

      Hi,

       

      I have a rich:tree holding some nodes. For the selected node I want to create a component (javax.faces.HtmlInputText, org.richfaces.Calendar and some others) next to the tree. The component type depends on the selected tree node.

       

      To create the components I am using the code:

       

      {code}

          public void createInputComponent()
           {
               FacesContext context = FacesContext.getCurrentInstance();
               Application application = context.getApplication();
               ExpressionFactory factory = application.getExpressionFactory();
               ValueExpression expression =  factory.createValueExpression(context.getELContext(), "#{myBean.value}",  String.class);
              

              UIInput input = (UIInput)  application.createComponent(cp.getVisualComponent());

              input.setValueExpression("value", expression);
               input.setId("paramValue");
               input.getChildren().add(support);

       

               setInputPanelGroup((HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE));
               mInputPanelGroup.getChildren().clear();
               mInputPanelGroup.getChildren().add(input); 
           }

      {code}

       

      The tree is defined like this:

       

      {code:xml}

           <rich:tree id="parametersTree"
                  value="#{myBean.parameterNodes}"
                  nodeSelectListener="#{myBean.processTreeSelection}"
                  reRender="paramValuePanel, paramValueInputPanel"
                  ajaxSubmitSelection="true"
                  adviseNodeSelected="#{myBean.nodeSelected}"
                  var="parameterName" >
                  <rich:treeNode>
                      <h:outputText value="#{parameterName}" />
                  </rich:treeNode>
              </rich:tree>

      {code}

       

      I am setting the new components in a panel group defined like this:

       

      {code:xml}

           <rich:panel id="paramValueInputPanel" >
                      <h:panelGroup id="paramValueInputs" binding="#{myBean.inputPanelGroup}" layout="block" >
                      </h:panelGroup>
              </rich:panel>

      {code}