0

I am trying to bind h:panelGroup to UIComponent (HtmlPanelGroup) code like a:

p.s I am using faces-config.xml

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.faces.component.html.HtmlOutputLabel;
import javax.faces.component.html.HtmlPanelGroup;
import javax.faces.event.ActionEvent;


    @ViewScoped
    public class PanelGroupUpdater1 {

    private HtmlPanelGroup hpg0;

        @PostConstruct
        public void init(){

            hpg0=new HtmlPanelGroup();
            hpg0.setLayout("block");
            hpg0.setStyleClass("myBindedPanelGroup0");

            HtmlOutputLabel l = new HtmlOutputLabel();
            //l.setValue("Synched binded panel group : ");
            hpg0.getChildren().add(l);


        }

      int h;
        public void addLabelBindedSynched(ActionEvent event) {
            //update panelgroup by its binding


                HtmlOutputLabel l = new HtmlOutputLabel();
                l.setValue("added:"+(++h)+";");
                this.hpg0.getChildren().add(l);     
        }

    }

and the WebContent/test/bindingtest.xhtml

<h:body>

<f:view>


Binded panel group (hpg0) : <br/>
<h:panelGroup id="myBindedPanelGroup0" binding="#{panelGroupUpdaterBean1.hpg0}" layout="block">
</h:panelGroup>

<h:form>
    <h:commandButton value="Add Label (binded)" actionListener="#{panelGroupUpdaterBean1.addLabelBindedSynched}" update=":myBindedPanelGroup0" />
</h:form>

</f:view>

</h:body>

the thing is I can add label to panelgroup just once but all next adding attempts I get this exception java.lang.IllegalStateException: CDATA tags may not nest .

So my question is... what causes the issue and how to fix that?

Thanks

cbhogf
  • 91
  • 13
  • I just tried to find out deeper; Seems like the issue related to this http://stackoverflow.com/a/14917453/6312069 answer I just found; The bean needs @RequestScoped annotation, as I could get it (correct me if I am wrong); But still is there is a way to use session in binded bean cause I'd like to use session scoped not the request scoped only :S – cbhogf Aug 09 '16 at 22:17
  • @BalusC Maybe but I am using ui as a field and instantiate it in postconstruct-ed method; The answer here http://stackoverflow.com/q/3409053 doesn't do this kind of binding... so maybe that's why it's OK with ViewScoped :S I tried to use viewscoped as well but it gives me ID duplicate issue, as I can remember; Comment please – cbhogf Aug 10 '16 at 19:26
  • The answer also clearly explains why you shouldn't at all use `binding` and create components this way and shows several correct approaches of "dynamically creating components". It looks like you're strongly Swing/GWT minded and don't grasp the point of XHTML+XML in order to create and define a (dynamic) component tree. – BalusC Aug 15 '16 at 09:03
  • @BalusC if binding exists in jsf why not to use it? Modify UI by finding it by id etc maybe that's just another way :S It is quite not interesting just inject text into static ui on some event; Moreover I am not sure jsf dicts really strict rules about how UI must be modified which is quite generic; And I am not sure my question is duplicate cause the question http://stackoverflow.com/a/14917453/6312069 doesn't bind div like container etc; I like the binding functionality cause it makes jsf closer to OOP style I guess :) – cbhogf Aug 15 '16 at 20:27
  • @BalusC BTW I could find with this answer stackoverflow.com/a/14917453/6312069 my code didn't work cause of viewscoped annotation so I changed it to requestscoped, as recommended, and it worked; Thank you, BalusC, very useful answer touching many interesting pointes I liked it; Anyway, I wanted to ask is it OK using sessionscoped in case of my question code or how to cache server side data in a more optimal way when I use requestscoped? – cbhogf Aug 15 '16 at 22:15

0 Answers0