开发者

Creating dynamic controls in jsf managed bean?

开发者 https://www.devze.com 2022-12-21 23:24 出处:网络
I want to dynamically create object of HtmlDivElement in my jsf managed bean and add it to panel but it seems that Html开发者_开发知识库DivElement is interface. So, how can i do it?This is a pretty ma

I want to dynamically create object of HtmlDivElement in my jsf managed bean and add it to panel but it seems that Html开发者_开发知识库DivElement is interface. So, how can i do it?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号