0

Created a TagHandler and added a facelet. The facelet content is still not evaluated. The html code contains ui:fragment text.

    @Override
    public void encodeBegin(FacesContext context) throws IOException{
    ResponseWriter writer = context.getResponseWriter();
              content = benefits.getContent(type);  
    writer.write(content);  
}

  <content type="short">
    <data><![CDATA[         
    <ui:fragment rendered="#{true}">
        <a id="" href="a.xhtml>
    </ui:fragment>
    <ui:fragment rendered="{false}">
        <a id="" href="b.xhtml">
    </ui:fragment>
    <img src="a.png"  alt="" />
  </a>  ]]></data>

  public class CardHolderBenefitsTagHandler extends TagHandler {

 private final TagAttribute src;

public CardHolderBenefitsTagHandler(TagConfig config) {
    super(config);
    TagAttribute attr = null;
    attr = this.getAttribute("src");            
    this.src = attr;

}

public void apply(FaceletContext ctx, UIComponent parent)
        throws IOException {
    String path = this.src.getValue(ctx);

    VariableMapper orig = ctx.getVariableMapper();
    ctx.setVariableMapper(new VariableMapperWrapper(orig));
    try {
        this.nextHandler.apply(ctx, null);
        ctx.includeFacelet(parent, path);
    } catch (IOException e) {           
        throw new TagAttributeException(this.tag, this.src,
                "Invalid path : " + path);
    } finally {
        ctx.setVariableMapper(orig);
    }
 }
 }
user679526
  • 845
  • 4
  • 16
  • 39

1 Answers1

1

You're making a conceptual mistake. The HTTP response writer is intented to write HTML code, not to write JSF code. The webbrowser namely understands only HTML, not JSF. All regular JSF components and renderers also just write HTML code to the response writer. Open a normal JSF page in webbrowser and do rightclick and view source. If JSF did its job right, you'll see that it's one and all HTML, completely free of any JSF code.

Essentially, you need to create a Facelets taghandler instead of an JSF UI component in order to manipulate the JSF component tree with new JSF components based on XML source.

The answer to the following question contains a Hello World tag handler. This must get you started: Custom Facelet component in JSF.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Do we create a new TagHandler and read the xml file content to evaluate the content? – user679526 Aug 23 '13 at 16:02
  • Yes, that's correct. Consider using `FaceletContext#includeFacelet()`. See also source code of ``, the `IncludeHandler` class. – BalusC Aug 23 '13 at 16:14
  • I have changed the above question. Added a taghandler which calls the facelet. This does not resolve the issue of evaluating the ui:fragment code. – user679526 Aug 23 '13 at 18:27