创建了一个 TagHandler 并添加了一个 facelet。facelet 内容仍未评估。html 代码包含 ui:fragment 文本。
@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);
}
}
}