1

i try to define a custom component with jsf2.1. The component must be update after button click. The component have a rendered attribute, default to false, that is update on the button click. This is my code.

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

The code that trigger the update.

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

with this code, bean.booleanCondition is set to true, but actionBar component is never display. If i wrap the component inside a it works.

this is my ActionBar component class :

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

How could i make it work?

Scandinave
  • 1,388
  • 1
  • 17
  • 41

1 Answers1

1

You can not update component with renderedattribute. Here you have explanation and solution: update attribute does not update component Generally, wrap up rendered component in <h:panelGroup> and update it.

Community
  • 1
  • 1
Szarpul
  • 1,531
  • 11
  • 21