How To Add BotDetect CAPTCHA Protection to JSF Forms

Unlike Recaptcha the Stalker -- BotDetect CAPTCHA works in China! Licensable source-code; self-hosted -- doesn't stalk -- nor does it slurp your form-data! Think: GDPR & LGPD!

Protecting your JSF forms with BotDetect Java Captcha slightly differs from JavaServer Pages protection but is still straightforward whether you use standard or Facelets presentation technology.

You can also see how BotDetect Captcha protection has been added to various kinds of JSF forms and projects by running the BotDetect Captcha JSF integration code examples coming with the BotDetect installation. You can also reuse the code example source code that fits your requirements.

Here we will discuss only integration steps which differ from JavaServer Pages integration steps since including BotDetect Library in the Classpath and registering SimpleCaptchaServlet steps are the same regardless of framework.

Add BotDetect Java CAPTCHA Library Dependency

Here is how to add BotDetect Java CAPTCHA Library dependency in various dependency management scenarios:

To manually add BotDetect Captcha library to classpath, copy the following jar files from BotDetect Java download package to application's WEB-INF/lib folder:

  • botdetect-4.0.beta3.5.jar
  • botdetect-servlet-4.0.beta3.5.jar
  • botdetect-jsp20-4.0.beta3.5.jar
  • botdetect-jsf20-4.0.beta3.5.jar
  • hsqldb.jar

In case your application uses JSF 1.2 you will need to copy the botdetect-jsf12-4.0.beta3.5.jar file instead of botdetect-jsf20-4.0.beta3.5.jar file.

To share BotDetect Captcha among multiple applications, these BotDetect jar files above should be copied into 'lib' directory of web container or application server's domain.

Register SimpleCaptchaServlet

Update your application configuration (web.xml) file.

  <servlet-name>BotDetect Captcha</servlet-name>
  <servlet-name>BotDetect Captcha</servlet-name>

Configure Captcha options

Configure captcha options in WEB-INF/botdetect.xml configuration file. You can find a full list of available Captcha configuration options and related instructions at the Captcha configuration options page.

<?xml version="1.0" encoding="UTF-8"?>
<botdetect xmlns="" 




To protect your JSF form use dedicated simpleJsfCaptcha tag.
Adding simpleJsfCaptcha tag to JSF form is pretty straightforward but there are some differences between standard JSF (.jsp) and Facelets (.xhtml) presentation techologies:

  • declare taglib at the begining of the .jsp file:
  • <%@taglib prefix="botDetect" uri=""%>
  • add attribute prependId="false" to <h:form> opening tag
    this is not mandatory but enables some added functionality to simpleJsfCaptcha tag
  • within the form insert:
  • <h:outputLabel for="captchaCode" 
      value="Retype the characters from the picture:"/>
    <botDetect:simpleJsfCaptcha id="exampleCaptcha" 
    <h:inputText id="captchaCode" value="#{captchaExampleBean.captchaCode}"/>

When you open your form in a browser, the above declarations should render as:

BotDetect CAPTCHA added to an JSP page

If you are adding Captcha protection to multiple JSF forms in the same website, you should take care to give each one a unique name (e.g. "registrationCaptcha", "commentCaptcha", ...) in the SimpleCaptcha object constructor.

In order to perform CAPTCHA validation SimpleJsfCaptcha tag must be bound with the corresponding property of the backing bean. This backing bean property should be of the SimpleJsfCaptcha type, and include both getter and setter access:

import botdetect.web.jsf.SimpleJsfCaptcha;

private SimpleJsfCaptcha captcha;

public SimpleJsfCaptcha getCaptcha() {
   return captcha;

public void setCaptcha(SimpleJsfCaptcha captcha) {
   this.captcha = captcha;

Check is the Visitor a Human on Form PostBack

Once the Captcha challenge is displayed on your form, the code processing form submissions can check if the Captcha was solved successfully and deny access to bots.

Add CAPTCHA Validation Logic to Backing Bean

When the form is submitted, the Captcha validation result must be checked and the protected action (user registration, comment posting, email sending, ...) only performed if the Captcha test was passed. For example, this code should be part of or invoked from backing bean method declared in <form> action attribute:

boolean isHuman = captcha.validate(captchaCode);
if (isHuman) {
  correctLabelVisible = true;
  incorrectLabelVisible = false;
} else {
  correctLabelVisible = false;
  incorrectLabelVisible = true;

Please Note

BotDetect Java Captcha Library v4.0.Beta3.5 is an in-progress port of BotDetect 4 Captcha, and we need you to guide our efforts towards a polished product. Please let us know if you encounter any bugs, implementation issues, or a usage scenario you would like to discuss.