Close a PrimeFaces dialog when no validation messages are available

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.

<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>

2 Comments

  • Radu - 2010/03/19

    Nice solution!

    However, adding a modal=”true” attribute to the dialog will not clear the page mask after dialog is made invisible. You will have to refresh the page to be able to use the application again.

    Reply
  • Herick - 2011/05/16

    I was looking for the reason of why my dialogs can’t be reopened after a primefaces upgrade, and after 2 months I found the answer here.

    The problem now is, how can I maintain the “modal=true” if I have to check the facesMessage to look for errors? Anyway, at least the problem was explained.

    Thank you Radu.

    Reply

Leave a Reply

green red blue grey