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:)
<p:captcha publicKey="your-public-key"/>
4. Configuration
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"/>
Online Demo
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.
I tried but it failed to show the page..
com.sun.facelets.tag.TagException: /pages/security/login.xhtml @61,70 Tag Library supports namespace: http://primefaces.prime.com.tr/ui, but no tag was defined for name: captcha
at com.sun.facelets.compiler.CompilationManager.pushTag(CompilationManager.java:193)
questions: does it also works together richfaces ? I just added the primefaces lib to my lib folder, configured the tags and launched..
my snapshot demo is here:
ops, it failed to add the link: http://fgaucho.dyndns.org:8080/cejug-classifieds-richfaces
Hi Felipe,
I’ve tested PrimeFaces with RichFaces, they do fine together, even combining ajax stuff works fine. So no known problem on that part.
Captcha components is added after 0.8.0 so it’s not in the jar you’re using, if you try a 0.8.1-SNAPSHOT(build from source, no nightly builds yet) it’ll work.
no luck
I tried:
com.prime.primefaces
primefaces-ui
0.8.1-SNAPSHOT
prime-repo
Prime Technology Maven Repository
http://repository.prime.com.tr/
default
error:
Missing:
———-
1) com.prime.primefaces:primefaces-ui:jar:0.8.1-SNAPSHOT
Try downloading the file manually from the project website.
0.8.1 Snapshots were not available in prime repo so it’s normal that maven can’t find it. However I’ve just deployed the latest snapshot. Could you please try again? Also we’re planning to set the stuff to publish nightly builds soon.
One more thing, PrimeFaces support forum is the best way to ask for help in cases like this:)
http://primefaces.prime.com.tr/forum/