Migrate composite-component to custom-component
Asked Answered
P

1

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?

Partizan answered 30/5, 2013 at 7:7 Comment(2)
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 <p:panel> in your custom component? Or are you concretely asking how to reuse the default encoder (renderer) of <p:panel> 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.Recall
@Recall 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.Partizan
B
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.

Browder answered 5/7, 2013 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.