开发者

Creating dynamic controls in jsf managed bean?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜