【问题标题】:How to refresh a custom component with primefaces update or jsf render? [duplicate]如何使用 primefaces 更新或 jsf 渲染刷新自定义组件? [复制]
【发布时间】:2015-03-12 07:41:57
【问题描述】:

我尝试使用 jsf2.1 定义一个自定义组件。单击按钮后必须更新组件。该组件有一个 render 属性,默认为 false,即单击按钮时更新。这是我的代码。

<cu:ActionBar id="actionBar" rendered="#{bean.booleanCondition}">
    <!-- some code inside !-->
</cu:ActionBar>

触发更新的代码。

<p:commandButton id="myButton" actionListener="#{bean.foo} update=":actionBar"/>

使用此代码,bean.booleanCondition 设置为 true,但 actionBar 组件永远不会显示。如果我将组件包装在 a 它可以工作。

这是我的 ActionBar 组件类:

@FacesComponent(value = "ACTION_BAR")
public class ActionBarComponent extends UIPanel {

       @Override
       public void encodeBegin(FacesContext ctx) throws IOException {
             if (ctx == null) {
                    throw new NullPointerException();
             }
             ResponseWriter writer = ctx.getResponseWriter();

             writer.startElement("div", this);
             if (this.getAttributes().get("id") != null) {
                    writer.writeAttribute("id", this.getAttributes().get("id"), "id");
             }
             String styleClass = this.getAttributes().get("styleClass") != null ? "" : " " + this.getAttributes().get("styleClass");
             writer.writeAttribute("class", "actionBar" + styleClass, null);
             writer.startElement("form", this);
             writer.writeAttribute("enctype", "application/x-www-form-urlencoded", null);
             writer.writeAttribute("method", "post", null);
             writer.writeAttribute("name", "actionBarForm", null);
             if (this.getAttributes().get("id") != null) {
                    writer.writeAttribute("id", this.getAttributes().get("id") + ":" + this.getAttributes().get("id") + "Form", "id");
             }
             writer.writeAttribute("action", ctx.getExternalContext().getRequestContextPath() + ctx.getExternalContext().getRequestServletPath(), null);
             writer.startElement("div", this);
             writer.writeAttribute("class", "actionBarGroup", "class");
             writer.startElement("span", this);
             writer.append("Actions :");
             writer.endElement("span");

       }

       @Override
       public void encodeEnd(FacesContext ctx) throws IOException {
             if (ctx == null) {
                    throw new NullPointerException();
             }
             ResponseWriter writer = ctx.getResponseWriter();

             writer.endElement("div");
             writer.endElement("form");
             writer.endElement("div");
       }
}

我怎样才能让它工作?

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    您不能使用renderedattribute 更新组件。这里有解释和解决方案:update attribute does not update component 通常,将rendered 组件包裹在&lt;h:panelGroup&gt; 中并更新它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 2012-07-26
      • 2018-01-11
      • 2011-02-06
      • 2012-09-13
      • 1970-01-01
      相关资源
      最近更新 更多