I’m posting this to memorize a PrimeFaces pattern for reuse. The visibility of PrimeFaces dialog panel can be controlled using the visible attribute. JavaScript widget.open() or widget.hide() modify the visibility state as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<p:dialog widgetVar="widget" id="dialog"
  visible="#{not empty facesContext.maximumSeverity}">
  <f:facet name="header">
      <h:outputText value="Form" />
  </f:facet>
  <h:form>
      <h:panelGrid columns="3">
          <h:outputLabel for="input" value="Input" />
          <h:inputText id="input" label="Input" required="true" value="VALUE" />
          <h:message for="input" />
      </h:panelGrid>

      <h:panelGroup>
          <!-- update the form for the case we get validation errors -->
          <p:commandButton value="Update" update="dialog"/>
      </h:panelGroup>
  </h:form>
</p:dialog>

Comments