JBoss

Keep Rich-Faces modal panel open when form validation errors occur

Keeping a model panel open after form validation produced errors is a bit puzzling. I found some good hints in the Rich-Faces Developer Guide
-you need a few lines of JavaScript though;(
The guide refers to a Rich-Faces Wiki article and a forum posting.

I have slightly modified the solution. On top of the page (outside the modal panel) I added a hidden form field that just indicates if validation messages exist.

<a4j:outputPanel ajaxRendered="true">
	<h:form style="display:none" prependId="false">
		<h:inputHidden id="hasMessages" value="#{menuAdminController.hasMessages}" />
	</h:form>
</a4j:outputPanel>

The method property hasMessages is implemented as follows:

public boolean isHasMessages() {
	return FacesContext.getCurrentInstance().getMessages().hasNext();
}

The button uses the oncomplete attribute to test the hasMessages element with a little bit of Javascript.

<a4j:commandButton value="#{applicationResources['command.ok']}" action="#{menuAdminController.editedObject.store}"
				oncomplete="if (document.getElementById('hasMessages').value=='false') Richfaces.hideModalPanel('editPanel');" />

WordPress.org

© 2010 Martin Ahrer – together we'll make IT - Business WordPress Theme by ThemeShift