简体   繁体   中英

Migrate composite-component to custom-component

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM