6

I have to migrate a composite-component to a custom-component. This example is rather simplified, but demonstrates the problem: the childs of my component (my:test) need to be rendered in another component. The composite my:testC, as an example which I don't want to use, would look like this

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

Obviously (at least I hope I'm correct with this assumption) I can not simply render the 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 in a way like this:

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

The output should be the same than using my:testC: some Text rendered in a PrimeFaces panel. How can I encode the usage of p:panel in my Java class?

Thor
  • 6,607
  • 13
  • 62
  • 96
  • I do not understand the concrete problem/question (in fact, there's nowhere a concrete question). Are you concretely asking how to encode the same output of `` in your custom component? Or are you concretely asking how to reuse the default encoder (renderer) of `` for that part? The children is not the problem at all as `encodeChildren()` does it all automatically, howerver the last sentence of the first paragraph seems to indicate otherwise, which is confusing. – BalusC Jun 07 '13 at 13:38
  • @BalusC Thank you for looking in this issue. I have updated the question, hopefully it is better to understand now. To answer your question: I'm trying to encode the same output of `p:panel`. – Thor Jun 07 '13 at 16:21

1 Answers1

0

You observed that correctly. You cannot simply render "p:panel" or any other jsf markup in a custom component.

What you can do however:

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

  • Directly render HTML

  • Use the facelet API that should be available in the current JSF (I have never actually worked with that)

  • Use any other template processing like velocity or freemarker to render HTML.