-
1. Re: component binging + dynamic component init
nbelaevski May 10, 2010 7:33 AM (in response to svkap)Hi Svetoslav,
JavaDoc says that setter is not called if getter returns non-null component value.
-
2. Re: component binging + dynamic component init
svkap May 10, 2010 8:02 AM (in response to nbelaevski)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
nbelaevski May 10, 2010 9:49 AM (in response to svkap)How does page & bean code look like?
-
4. Re: component binging + dynamic component init
mpickell May 10, 2010 2:32 PM (in response to svkap)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
svkap May 10, 2010 5:27 PM (in response to mpickell)Here is a part of my code:
private void initPanelList() { // add list all link HtmlPanelGroup panelGroup = new HtmlPanelGroup(); panelGroup.setLayout("block"); panelGroup.setStyleClass("UIPortrait"); HtmlGraphicImage image = new HtmlGraphicImage(); image.setUrl("/img/px.gif"); image.setStyle("width:50px;height:50px;"); HtmlOutputLink textLink = new HtmlOutputLink(); textLink.setValue("./test.jsf"); HtmlOutputText textLinkTxt = new HtmlOutputText(); textLinkTxt.setValue("List All"); textLink.getChildren().add(textLinkTxt); panelGroup.getChildren().add(image); panelGroup.getChildren().add(textLink); panelist.getChildren().add(panelGroup); } public void setPanelList(HtmlPanelGroup panelList) { this.panelList = panelList; initPanelList(); }
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; initPanelList(); } }
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
nbelaevski May 11, 2010 5:34 AM (in response to svkap)Svetoslav,
I'd recommend to try creating components by action and use binding only to get parent component for the created components into bean.