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



      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




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









      This is the code for the tree:



           <rich:tree id="parametersTree"



              reRender="paramValuePanel, paramValueInputPanel"



              var="parameterName" >


                  <h:outputText value="#{parameterName}" />





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


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





      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?