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.


	
		
	

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.


7 Comments

  • Andreas - 2009/06/23

    This will also work:

    oncomplete=”if (#{facesContext.maximumSeverity==null}) Richfaces.hideModalPanel(‘editPanel’)”

    Reply
  • Alex C - 2009/06/26

    Thanks for the great article. How do you show the modalPanel when the user clicks the Submit button on a page? All the examples I’ve seen have a separate link or button for it. What we need is to have it display the validation errors in the modalPanel only if there were errors; otherwise say “Please wait…” while it loads the button’s action and redirects. Thanks.

    Reply
  • ralph - 2009/09/01

    Nice solution. I also succeeded with the
    oncomplete=”if (#{facesContext.maximumSeverity==null})
    method.
    But in my case I was forced to add also a reRender attribute to get the validation errors displayed in the modalPanel

    so my command button looks like this:

    Reply
  • Aristide - 2009/10/16

    I use the both solution but none does not work. Can you for help send me your whole code please ? thanks in advance.

    Reply
    • Martin Ahrer - 2009/10/16

      That’s property of a customer, so I can’t post a complete solution. Sorry!

      Reply
  • Divya - 2010/04/29

    When is the hasMessages attribute set.

    Reply
    • Martin Ahrer - 2010/05/19

      It is part of the form above and set when the expression #{menuAdminController.hasMessages} is evaluated

      Reply

Leave a Reply

green red blue grey