I am creating a JSF form where I have an email field. I need to validate the email format and check for uniqueness against DB.
I need to check this when the enduser has entered the email field. If it’s present in the DB, then we need to change the field color to red and otherwise to green. I would like to perform this by ajax.
I have seen examples in PHP, but it’s not clear to me how to do it in JSF.
For general email format validation, you could use
<f:validateRegex>.To perform validation on blur, add
<f:ajax event="blur">.For unique email validation, implement the JSF
Validatorinterface according its contract.and register it by
<f:validator>To change component’s style, you could use EL in
styleorstyleClassattribute.You do not necessarily need jQuery for this. It would also have been less robust as jQuery runs at the client side, not the server side (you know, endusers have 100% control over what runs at the client side).