我正在使用动态仪表板,用户可以根据需要固定和删除项目。现在我有一个问题,我想从支持bean中将现有的复合组件添加到视图中。我试图找到从互联网上做到这一点的正确方法,但迄今为止没有成功。下面是简单的复合组件我想补充:以编程方式在支持bean中创建和添加复合组件
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<cc:interface>
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<h:outputText value="TEST"/>
</cc:implementation>
</html>
这里是一个要返回复合组件的代码:
public static UIComponent getCompositeComponent(String xhtml, String namespace) {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
Resource componentResource = app.getResourceHandler().createResource(xhtml, namespace);
UIPanel facet = (UIPanel) app.createComponent(UIPanel.COMPONENT_TYPE);
facet.setRendererType("javax.faces.Group");
UIComponent composite = app.createComponent(fc, componentResource);
composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facet);
return composite;
}
,这里是我如何使用功能:
Column column = new Column();
UIComponent test = HtmlUtil.getCompositeComponent("test.xhtml", "comp");
column.getChildren().add(test);
但是在列内没有任何内容。任何想法如何做到这一点?我不想用render =“#{bean.isThisRendered}”的方式,因为它不适合我的用例。
出于兴趣(题目是可怕的严重覆盖,这会给我带来前进光年):你在哪里调用
所以,在你的具体的例子,按如下方式使用它3行调用'HtmlUtil.getCompositeComponent'? – 2017-06-21 16:27:56