mojarra icon indicating copy to clipboard operation
mojarra copied to clipboard

Bean Validator is called multiple times

Open javaserverfaces opened this issue 8 years ago • 8 comments

When using Bean validation, component binding and ajax together, the validation is added at every ajax call to the validator list of the component. This results in multiple calls and displaying the validation message multiple times.

Example:

<h:inputText id="input" validator="#{bean.validate}" binding="#{bean.component}">
  <f:ajax />
</h:inputText>

Affected Versions

[2.2.12]

javaserverfaces avatar Apr 07 '16 18:04 javaserverfaces

Reported by mwalliczek

javaserverfaces avatar Apr 07 '16 18:04 javaserverfaces

mwalliczek said: Environment: Apache Deltaspike 1.5.4, Primefaces 5.3.5, Omnifaces 2.2

javaserverfaces avatar Apr 07 '16 18:04 javaserverfaces

zhangxinyuan said: Hi, Can you provide a test war application for this bug?

javaserverfaces avatar Aug 09 '16 08:08 javaserverfaces

Was assigned to ZhangXinyuan

javaserverfaces avatar Apr 07 '16 18:04 javaserverfaces

This issue was imported from java.net JIRA JAVASERVERFACES-4122

javaserverfaces avatar May 02 '17 10:05 javaserverfaces

Please see this important message regarding community contributions to Mojarra.

https://javaee.groups.io/g/jsf-spec/message/30

Also, please consider joining that group, as that group has taken the place of the old [email protected] mailing list.

Thanks,

Ed Burns

edburns avatar Oct 29 '17 03:10 edburns

I have the same issue. f:ajax even is not necessary to reproduce it. Affected version 2.3.3.

@Getter @Setter private transient HtmlInputText myField; public void validate(final FacesContext context, final UIComponent component, Object value) {...}

When validate is called, myField has 2 validators attached, instead of only 1. After each submit another additional vaildator is appended - using javax.faces.view.ViewScoped.

Only MethodExpression validators seem to be affected!

svenhaag avatar Dec 19 '17 12:12 svenhaag

This usually happens when the binding attribute incorrectly references a bean which is not in the request scope. In other words, this usually only happens when the whole physical component tree is incorrectly saved in the HTTP session and shared across multiple HTTP requests. This is against the recommendations in JSF specification. See also https://stackoverflow.com/q/14911158/157882

BalusC avatar May 26 '20 10:05 BalusC