3 Replies Latest reply on Jun 15, 2010 7:55 AM by Ilya Shaikovsky

    How to create components dynamically on treeNode selection?

    Gen Sys Newbie

      Hi,

       

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

       

      I am using this code to create the components

       

       

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


              setInputPanelGroup((HtmlPanelGroup)application.createComponent(HtmlPanelGroup.COMPONENT_TYPE));

              mInputPanelGroup.getChildren().clear();

              mInputPanelGroup.getChildren().add(input);

          }

      {code}

       

       

      This is the code for the tree:

       

      {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}

       

      This is the code for the PanelGroup - the placeholder for the dynamically created components.

       

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

              </h:panelGroup>

          </rich:panel>

      {code}

       

      I call the createInputComponent() method in the processTreeSelection() method of the bean - nodeSelectListener of the tree. The problem is that the newly created component is not shown.

       

      If I call the createInputComponent() method in the getInputPanelGroup() (getter for the binding) or in the myBean contrutor, then only the first created component is shown, and it does not change when someother node from the tree is selected.

       

      What I am doing wrong? I was thinking that the call in processTreeSelection() method should be sufficient?