如何使用primefaces update或jsf render刷新自定义组件?
我尝试用jsf2.1定义一个自定义组件。该组件必须在单击按钮后更新。该组件有一个渲染属性,默认为false,即单击按钮时更新。这是我的密码如何使用primefaces update或jsf render刷新自定义组件?,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我尝试用jsf2.1定义一个自定义组件。该组件必须在单击按钮后更新。该组件有一个渲染属性,默认为false,即单击按钮时更新。这是我的密码 <cu:ActionBar id="actionBar" rendered="#{bean.booleanCondition}"> <!-- some code inside !--> </cu:ActionBar> 如何使其工作?您不能使用呈现属性更新组件。这里有解释和解决方案:通常,将呈现的组件包装在中并更新
<cu:ActionBar id="actionBar" rendered="#{bean.booleanCondition}">
<!-- some code inside !-->
</cu:ActionBar>
如何使其工作?您不能使用
呈现属性更新组件。这里有解释和解决方案:通常,将呈现的组件包装在
中并更新它
<p:commandButton id="myButton" actionListener="#{bean.foo} update=":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");
}
}