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.

1
2
3
4
5
<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:

1
2
3
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.

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

Comments