0

I am using bean validation with annotations in my JSF project. I was wondering, how to create annotations for password confirmation and how to validate that an email doesn't exist in database?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

1 Answers1

3

This kind of validation is not really applicable on entities. User entities do not hold double password fields, instead they hold just a single password field. Also entities do not necessarily hold an email field with a value which do not exist in the DB. You would end up with false errors whenever you want to edit an existing entity.

I suggest you to do this validation in the view side, right before the entity is to be persisted in the DB. In JSF you can use Validator for this. You can find examples of a password confirmation validator in the answers on this question: How validate two password fields by ajax?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • i followed the example here: http://balusc.blogspot.com/2007/12/validator-for-multiple-fields.html but it shows me the error message with blue color and out of the form, not showing a message beside the confirmation field, any ideas ? – Mahmoud Saleh Sep 22 '11 at 16:13
  • This means that you don't have a `` on confirm field or were using ajax and didn't re-render that field. Please note that that article is almost 4 years old and targeted on JSF 1.2 without ajaxical fuss. – BalusC Sep 22 '11 at 16:17
  • i don't want to validate the password with ajax, just want normal validation on form submit, any links for how this is done in jsf 2, is it similar to your old post ? – Mahmoud Saleh Sep 23 '11 at 17:13
  • Yes, it should work equally fine in JSF2. The linked answer also, you just have to remove `` stuff. It only validates the other way round. The message appears for the password field, not for the confirm field. – BalusC Sep 23 '11 at 17:15