11.7.2. Adding a Captcha to a page

11.7.2. Adding a Captcha to a page

Adding a captcha challenge to a page is extremely easy. Seam provides a page-scoped component, captcha, which provides everything that is required, including built-in captcha validation. Here's an example:

<div>
    <h:graphicImage value="/seam/resource/captcha?#{captcha.id}"/>
</div>
  
<div>
    <h:outputLabel for="verifyCaptcha">Enter the above letters</h:outputLabel>
    <h:inputText id="verifyCaptcha" value="#{captcha.response}" required="true"/>
    <div class="validationError"><h:message for="verifyCaptcha"/></div>
</div>

That's all there is to it. The graphicImage control displays the Captcha challenge, and the inputText receives the user's response. The response is automatically validated against the Captcha when the form is submitted.