I work with a dynamic panel where users can attach and remove items as they wish. Now I have a problem that I want to add an existing compound component to the view from a backup bean. I tried to find the right way to do this from the Internet, but so far have not achieved anything. Here is a simple composite component that 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"> <cc:interface> </cc:interface> <cc:implementation> <h:outputText value="TEST"/> </cc:implementation> </html>
Here is the code that the composite component should return:
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 this is how I use the function:
Column column = new Column(); UIComponent test = HtmlUtil.getCompositeComponent("test.xhtml", "comp"); column.getChildren().add(test);
But nothing is displayed inside the column. Any ideas how to do this? I do not want to go with the rendered = "# {bean.isThisRendered}" method, because it does not fit in my use case.
drodil
source share