jrey
jrey

Reputation: 2183

Richfaces validation error on oncomplete script

i have the jsfunction

<a4j:jsFunction action="#{myBean.action}"
  data="#{myBean.data}" render="@form" execute="@form" name="openConfirm"  
onbeforedomupdate="openConfirmDialog(event.data);"></a4j:jsFunction>

I need open a confirm dialog(on the onbeforedomupdate, this works.. but open the dialog for all calls) I really need open the dialog form only if the jsf submit was validated. the validation errors shows when the form was not validated.

Whats the best way, to identify in the script if the JSF cycle returns validations errors?

i need something similar to onbeforedomupdate="if (event.validationError==false)showDialog();"

thanks a lot,

Upvotes: 0

Views: 1455

Answers (1)

Vasil Lukach
Vasil Lukach

Reputation: 3728

You can check for error like this

if (#{facesContext.maximumSeverity == null}) { openConfirmDialog(event.data); }

In case if you have more than 1 type of messages (error, warning, info) you can use

if (#{empty facesContext.messageList}) { openConfirmDialog(event.data); }

for checking validation messages before showing the dialog.

Example of usage in oncomplete:

oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('popup')}.show();}"

In case you want to react on warnings and errors but not on info messages use

oncomplete="if(#{facesContext.maximumSeverity.ordinal gt 0}) {#{rich:component('popup')}.show();}"

Additional information about last case here.

Upvotes: 5

Related Questions