Transfer a composite component to a custom component

I need to migrate a composite component to a custom component. This example is quite simplistic, but it demonstrates the problem: the children of my component ( my:test ) should be displayed in another component. Composite my:testC , as an example that I do not want to use, will look like this:

 <composite:implementation> <p:panel> <composite:insertChildren/> </p:panel> </composite:implementation> 

Obviously (at least I hope I'm right with this assumption). I cannot just display p:panel in encodeBegin .

 @FacesComponent("test") public class Test extends UIPanel { @Override public void encodeBegin(FacesContext context) throws IOException { // ?? } @Override public void encodeEnd(FacesContext context) throws IOException { // ?? } } 

I want to use my:test as follows:

 <my:test> <h:outputText value="some Text"/> </my:test> 

The output should be the same as when using my:testC : some text displayed in the PrimeFaces panel. How can I code using p:panel in my Java class?

+6
source share
1 answer

You noticed it right. You cannot just render the "p: panel" or any other jsf markup in a custom component.

What can you do:

  • Activate the subcomponents using the application instance, add it as a facet or child to your custom component, and then call it in your own renderer.

  • Directly render HTML

  • Use the facelet API, which should be available in the current JSF (I never worked with this)

  • Use any other template processing such as speed or freemarker to render HTML.

0
source

Source: https://habr.com/ru/post/946149/


All Articles