ReCaptcha meets JSF
January 29, 2009 6 Comments
PrimeFaces provides a captcha component based upon popular api reCaptcha. The component is actually an input component and has a built-in CaptchaValidator, this allows to integrate the reCaptcha well to JSF lifecycle since an invalid answer would cause a ValidatorException.
Getting started with captcha;
1. Sign up for keys
reCaptcha is a webservice and you need two keys in order to communicate with their verify server.
You can sign up and get these keys for domain. The link is : https://admin.recaptcha.net/recaptcha/createsite/
2. Add your private key in web.xml
RecaptchaValidator needs the private key when verifying the answer, for security reasons this is not set on the components
as an attribute but as a context param in web.xml
<context-param> <param-name>org.primefaces.ui.component.captcha.PRIVATE_KEY</param-name> <param-value>your-private-key</param-value> </context-param>
3. Add captcha to your JSF form
That’s it, now you can use captcha on the form you need to make sure the entity who submits the form is a human:)
Multiple languages and themes are also supported, following is a Turkish captcha with different theme.
<p:captcha theme="white" language="tr" publicKey="your-public-key"/>
You can check out the captcha examples online.
Note that captcha component is added after 0.8.0 release and is currently in 0.8.1-SNAPSHOT of PrimeFaces as a beta component.