1 Reply Latest reply on Jul 21, 2010 7:48 AM by serkan.s.eskici.online.nl

    Dynamically adding UIComponents in JSF

      Hello everyone!,


      I needed advice regarding adding components dynamically on a page.


      I have to add HtmlInput Text on a form on clicking an Add button.


      The text controls should be added dynamically.


      I have tried the following codes but could not render the text boxes.




      <h:form id="myForm2">
                     <h:panelGrid id="test" binding="#{parrainage.htmlPanelGrid}">
                          <h:inputText value="#{parrainage.email}" />
                     </h:panelGrid>
                     <s:button action="#{parrainage.addControlForEmail}" value="Ajouter2"></s:button>
      </h:form>



      private HtmlPanelGrid htmlPanelGrid;
      
      //getters and setters
      
      
      
      


      public String addControlForEmail() {
      
      
                htmlPanelGrid.getChildren().clear();
      
      
                UIColumn col = new UIColumn();
                HtmlOutputText ot = new HtmlOutputText();
                ot.setValue("test");
                col.getChildren().add(ot);
                HtmlInputText it = new HtmlInputText();
                it.setValue("");
                col.getChildren().add(it);
      
                if (htmlPanelGrid == null) {
                     htmlPanelGrid = new HtmlPanelGrid();
                }
                htmlPanelGrid.getChildren().add(col);
      
                return "someaction psgr";
           }



      Though the hmtlPanelGrid is binded, when the Ajouter2 button is clicked the htmlPanelGRid property is null.



      Ccan anyone advise what is wrong, please


      Rgds
      Neerou