I am working with a dynamic dashboard where users can pin and remove items as they like. Now I have a problem that I want to add existing composite component to the view from the backing bean. I've tried to find correct way to do this from the internet but no success so far. Here is the simple composite component I want to add:
<?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>
Here is the code which should return the composite component:
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;
}
And here is how I am using the function:
Column column = new Column();
UIComponent test = HtmlUtil.getCompositeComponent("test.xhtml", "comp");
column.getChildren().add(test);
But nothing is rendered inside the column. Any ideas how this could be done? I don't want to go with the rendered="#{bean.isThisRendered}" way because it does not fit in my use case.
HtmlUtil.getCompositeComponent
? – Reconciliatory