1

I have a form with lets say 3 fields:

  • password hint
  • password
  • password again

I have a bean, which contains these 3 fields, and I have a class level validator, which checks if the bean has a matching password and password again field. Imagine a pretty similar setup, like it is at https://github.com/AnghelLeonard/JSF-2.3/tree/master/JSF23ValidateWholeBeanExample

The problem which I face, that I enter a password hint, a password and a non matching password again. This case I get the whole form cleared, since as it seems to me, the WholeBeanValidator prevents JSF from saving any value into the model. The relevant code place is in com.sun.faces.ext.component.WholeBeanValidator.validate(FacesContext, UIValidateWholeBean, Object):

// Mark the components as invalid to prevent them from receiving
// values during updateModelValues
for (Entry<String, Map<String, Object>> validationCandidateEntry : validationCandidate.entrySet()) {
    invalidateComponent(validationCandidateEntry);
}

throw toThrow;

This case I think it would be good to keep the model values in the fields and to get the global error message. However the values do not come into the bean. Do I understand something wrong? Could you help me in this @BalusC :)?

Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113
  • Since it does not seem easy to solve this problem I could apply Springs @Validated annotation on the service methods as a workaround. – Gábor Lipták Apr 24 '19 at 14:43

1 Answers1

0

The Section What's new in JSF 2.3? - Class level bean validation on Arjan Tijms' Weblog cites:

In JSF the idea is that the model is not touched if validation fails.

This suggests that what you describe as a problem indeed works as intended.

If using ajax, maybe you should limit updating to messages and (if using primefaces) labels instead of updating the entire form including input fields.

Selaron
  • 6,105
  • 4
  • 31
  • 39