Creating dynamic controls in jsf managed bean?

后端 未结 1 1345
天命终不由人
天命终不由人 2021-01-15 09:19

I want to dynamically create object of HtmlDivElement in my jsf managed bean and add it to panel but it seems that HtmlDivElement is interface. So, how can i do it?

相关标签:
1条回答
  • 2021-01-15 09:53

    This is a pretty major confusion. The org.w3c.dom.html.HTMLDivElement is not a JSF component. This represents a W3 DOM element which has an entirely different purpose (JAXP, DOM parsing).

    You need a subclass of javax.faces.component.UIComponent (just click your way through the "Direct Known Subclasses" in the aforelinked Javadoc to find them all). To render a HTML <div> element, just use HtmlPanelGroup whose layout attribute is set to block.

    HtmlPanelGroup div = new HtmlPanelGroup();
    div.setLayout("block");
    someParentComponent.getChildren().add(div);
    

    which does effectively the same as the following in "static" JSF:

    <h:panelGroup layout="block" />
    
    0 讨论(0)
提交回复
热议问题