CAPTCHA with Seam in Three Minutes

Adding a CAPTCHA to a form using Seam is easy now that Seam is bundling jCaptcha.

The Seam documentaiton is good, and can be found in section 13.9 here:

If you used seam-gen to create your project, you will need to make a few changes.

First, you need to modify your project’s ant build script to deploy the captcha jar into your ear (or possibly .war). In the target “ear” of the build.xml file, you will find a list of many jar files being copied from your project’s lib directory into the ear. Simply add the captcha jar to that list, like this:

Now that the jar is deploying, you need to reference it in the application.xml file found under your project’s resources/META-INF directory. Add this entry:


If you used seam-gen you will find that the Seam Resource Servlet is already defined in your web.xml so the step defined in the documentation in section 13.9.1 is not necessary.

Now all you have to do is to add the tags into your page to firstly display the captcha image, and secondly take user input and validate the captcha. The validation process is handled out of the box by the Seam captcha component, so you do not need to handle that yourself. The documentation has this as an example captcha usage to paste into your page:

Enter the above letters

I am using icefaces in my latest project, so I added it like this:

Captcha *

Enter the above letters *

Once you deploy your project and start your application server, your page will look something like this:

Captcha registration page

And that is it. Very simple and easy.

Personally I find the default jCaptcha images to be very difficult to read (I picked an easy one above), so I will probably end up implementing a custom configured captcha using the directions in section 13.9.3 of the documentation. When that happens I will make it available here.



, ,



One response to “CAPTCHA with Seam in Three Minutes”

  1. hiran Avatar

    ty man!

    helped a lot =]

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By :