0
创建了一个TagHandler并添加了一个facelet。 facelet内容仍未评估。该html代码包含ui:片段文本。面对包含jsf组件的组件内容未评估
@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);
}
}
}
我们是否创建一个新的TagHandler并读取xml文件内容来评估内容? – user679526
是的,这是正确的。考虑使用'FaceletContext#includeFacelet()'。另请参见'IncludeHandler'类的''的源代码。 –
BalusC
我改变了上述问题。添加了一个调用facelet的taghandler。这不能解决评估ui:片段代码的问题。 – user679526