6 Replies Latest reply on May 11, 2010 5:34 AM by Nick Belaevski

    component binging + dynamic component init

    sv kap Newbie



      I have some troubles with component binding. I am creating some dynamic components on bean initialization. I am binding HtmlPanelGrid or HtmlPanel components and I am creating dynamic components as their children. However for some reason setters of the bound compoents are not always executed. As a result these components (the panels) do not have parent and therefor the dynamicly created components are not shown. I am initializing the components on @PostConstruct init method. I noticed that most of the times (at least on PanelGrids) if I have some other component inside the jsf page then it bound ok and it has parent (on @PostConstruct they are still null but at least the result is right). I suppose I am doing sth wrong.. Can u give me advice how this is done?

        • 1. Re: component binging + dynamic component init
          Nick Belaevski Master

          Hi Svetoslav,


          JavaDoc says that setter is not called if getter returns non-null component value.

          • 2. Re: component binging + dynamic component init
            sv kap Newbie

            I knew that I have to read the JavaDoc first .  What would you advise me? In @PostConstruct method my components are null.. So should I generate the dynamic components in the setter then?

            • 3. Re: component binging + dynamic component init
              Nick Belaevski Master

              How does page & bean code look like?

              • 4. Re: component binging + dynamic component init
                Matthew Pickell Newbie

                Couldn't you return a new HtmlPanelGroup() instead when you otherwise would be returning null?


                That would always return a component and would have no affect on your page layout (at least I think that's true with the little knowledge I have of your problem)

                • 5. Re: component binging + dynamic component init
                  sv kap Newbie

                  Here is a part of my code:



                          private void initPanelList() { 
                              // add list all link
                              HtmlPanelGroup panelGroup = new HtmlPanelGroup();
                              HtmlGraphicImage image = new HtmlGraphicImage();
                              HtmlOutputLink textLink = new HtmlOutputLink();
                              HtmlOutputText textLinkTxt = new HtmlOutputText();
                              textLinkTxt.setValue("List All");
                           public void setPanelList(HtmlPanelGroup panelList) {
                              this.panelList = panelList;


                  This is working fairly right. However there is 1 problem. The setter is executed a couple of times and on every execute I am making new queries to the database so I can build the dynamic components. In short it is not a good idea to have init method in the setter but for now I do not know where to put it. I cannot initialize new HtmlPanelGroup component because that way I am loosing the parent and if I want to find the correct parent component I have to traverse the whole component tree. My bean is @ViewScoped . I cannot use sth like that:



                           public void setPanelList(HtmlPanelGroup panelList) {
                              if (panelList == null) {   
                                   this.panelList = panelList;


                  because I am using another components along with RF and they are messing with the logic. By the way I have some troubles because of the second components and I will have to go with instantiating new HtmlPanelGroups on bean initialization. However, I hope that u could give me some advice and/or best practices for dynamic component creation.

                  • 6. Re: component binging + dynamic component init
                    Nick Belaevski Master



                    I'd recommend to try creating components by action and use binding only to get parent component for the created components into bean.