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); } } } 

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Do we create a new TagHandler and read the xml file content to evaluate the content?
Yes, that's correct. Consider using FaceletContext#includeFacelet(). See also source code of <ui:include>, the IncludeHandler class.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.