1

I want to validate that two fields on a page match (e.g. are the same exact email address). I don't have access to bean validation/validation groups. How should I go about validating that both addresses match?

Current thought is to put a validator on the second field and have it check that it matches the submitted value of the first. Is this the best way or is there a way to do this via configuration or some other means?

BestPractices
  • 12,738
  • 29
  • 96
  • 140
  • possible duplicate of [JSF2.0 doesn't support cross-field validation, is there a workaround?](http://stackoverflow.com/questions/6282466/jsf2-0-doesnt-support-cross-field-validation-is-there-a-workaround) – BalusC Apr 18 '12 at 15:01
  • Another example with ajax: http://stackoverflow.com/questions/7489893/how-validate-two-password-fields-by-ajax/7493527#7493527 – BalusC Apr 18 '12 at 15:05
  • Core JavaServer Faces Third Edition (3rd publishing) mentions an alternative that uses "Multi-Component Validation" using the postValidate event as a hook. Would this be a bad way to do it? – BestPractices May 01 '12 at 18:10
  • You could also do so. This would only tight couple the validator to the particular components, making it unreuseable for other use cases having the same requirement to validate multiple fields on equality. You'd basically need to copy the postvalidate event method and change the client IDs of the components of interest. – BalusC May 01 '12 at 18:19
  • Thanks, note, just realized you proposed this solution in another thread. Am linking it here: http://stackoverflow.com/questions/2456272/how-do-i-validate-two-components-value-are-same-or-not-jsf. – BestPractices May 01 '12 at 18:35
  • Have you tried ``? See also this showcase example: http://showcase-omnifaces.rhcloud.com/showcase/validators/validateEqual.xhtml – BalusC May 01 '12 at 22:00

1 Answers1

3

Here are an aggregate of all solutions so far:

See

1) JSF doesn't support cross-field validation, is there a workaround?

Ajaxified solution: 2) How validate two password fields by ajax?

PostValidate solution: 3) How do i validate two component's value are same or not? JSF

Community
  • 1
  • 1
BestPractices
  • 12,738
  • 29
  • 96
  • 140