不计算包含jsf组件的faces组件内容

  • 本文关键字:组件 faces 包含 jsf 计算 jsf-2
  • 更新时间 :
  • 英文 :


创建了一个TagHandler并添加了一个facelet。facelet内容仍未评估。html代码包含ui:片段文本。

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

您犯了一个概念错误。HTTP响应编写器旨在编写HTML代码,而不是编写JSF代码。Web浏览器即只懂HTML,不懂JSF。所有常规的JSF组件和渲染器也只是向响应编写器编写HTML代码。在Web浏览器中打开一个普通的JSF页面,右键单击并查看源代码。如果JSF做得对,您将看到它是一个完整的HTML,完全没有任何JSF代码。

从本质上讲,您需要创建一个Facelets标签处理程序,而不是JSF UI组件,以便使用基于XML源的新JSF组件来操作JSF组件树。

以下问题的答案包含一个Hello World标记处理程序。这必须让您开始:JSF中的自定义Facelet组件。

相关内容

最新更新