Pages

Thursday, December 6, 2012

Avoid closing a rich:popupPanel in richfaces when validation error occurs

In richfaces is common to have a rich:popupPanel that allows some input. If you must validate that input, you may want to left the panel open when a validation error occurs to show error messages. See the following picture that shows the case:




You can achieve this using the oncomplete attribute of the a4j:commandButton tag.


<rich:popupPanel 
  id="cp" minHeight="200" minWidth="450" modal="true"
     domElementAttachment="form" autosized="true">
....


   <a4j:commandButton
      value="Save"
      disabled="#{not securityScope.userInRole['ROLE_ABM']}"
  action="#{backingBean.save}"
      oncomplete="if (#{facesContext.maximumSeverity==null}) 
                  #{rich:component('cp')}.hide(); return false;">
   </a4j:commandButton>
...
</rich:popupPanel>

The important part is  #{facesContext.maximumSeverity == null} to ensure that there are no errors present after validation.

20 comments:

  1. Thanks man, it worked.

    ReplyDelete
  2. thank you, it's working without errors.

    ReplyDelete
  3. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. venta banderas institucionales

    ReplyDelete