JSF 2 - composite-component - Bean validation fails due to component with empty value


Staff member
i have a composite component (a captcha actually) which i use into a h:form.<br>
I have the following error when i click on the submit button of my h:form.

16 janv. 2013 10:02:06 javax.faces.validator.BeanValidator validate<br>
ATTENTION: cannot validate component with empty value: captcha:captchaText

Here is the xhtml code of the captcha's composite-component

&lt;!DOCTYPE html&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
  xmlns:composite="http://java.sun.com/jsf/composite" xmlns:xcc="http://java.sun.com/jsf/composite/components"&gt;

    &lt;composite:attribute name="id" type="java.lang.String" /&gt;
    &lt;composite:attribute name="imageWidth" type="java.lang.Integer" /&gt;
    &lt;composite:attribute name="imageHeight" type="java.lang.Integer" /&gt;
    &lt;composite:attribute name="imageClass" type="java.lang.String" /&gt;
    &lt;composite:attribute name="inputClass" type="java.lang.String" default="" /&gt;
    &lt;composite:attribute name="placeholder" type="java.lang.String" default="" /&gt;
    &lt;composite:attribute name="failureMessage" type="java.lang.String" default="Captcha validation failed" /&gt;

    &lt;composite:editableValueHolder name="captchaText" /&gt;

    &lt;h:inputText id="captchaText" required="true" styleClass="#{cc.attrs.inputClass}" placeholder="#{cc.attrs.placeholder}"
      autocomplete="off" maxlength="10"&gt;
      &lt;f:param name="failureMessage" value="#{cc.attrs.failureMessage}" /&gt;
      &lt;f:validateLength minimum="6" /&gt;
      &lt;f:validator validatorId="captchaValidator" /&gt;
    &lt;h:graphicImage id="captchaImage" alt="" style="margin-left:3px;" styleClass="#{cc.attrs.imageClass}" width="#{cc.attrs.imageWidth}"
      height="#{cc.attrs.imageHeight}" value="__captcha.jpg" /&gt;


Here is the Captcha's JSF Validator code.

import javax.faces.application.FacesMessage;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import net.paissad.waqtsalat.servlet.CaptchaServlet;

    public class CaptchaValidator implements Validator {

    public static final String VALIDATOR_ID = "captchaValidator";

    public void validate(final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {

        final String enteredValue = (String) value;
        final String expectedValue = (String) context.getExternalContext().getSessionMap()

        final boolean ok = (enteredValue != null) &amp;&amp; (enteredValue.equals(expectedValue));
        if (!ok) {
            String summary = (String) component.getAttributes().get("failureMessage");
             if (summary == null) summary = "";
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, summary));


I don't it is really necessary to show the code of the CaptchaServlet which build the real captcha image. All i can say is that it does work good. I inspired from this code <a href="http://javahunter.wordpress.com/2010/09/25/integrating-captcha-in-jsf-2-0/" rel="nofollow noreferrer" title="JSF 2 Captcha Servlet">here</a>.

here is basically how i used the composite-component in my form. (This is not my real use case btw)

    &lt;xcc:captcha id="captcha" imageClass="img-rounded" placeholder="#{i18n.Captcha_enter_code_here}" failureMessage="Captcha validation failed" /&gt;
    &lt;h:commandButton styleClass="btn btn-success" type="submit" value="#{i18n.Submit}"
            actionListener="#{accountRegistrationController.register}" action="success" /&gt;

The form is rendered like this (with French localization) :

<img src=" " alt="enter image description here">

I prefer using the composite-component + validator + servlet<br>
I prefer to avoid the use of a controller bean (@named / @RequestScoped) with a method for verifying the Captcha's entered value.

When i debug the Validator code in Eclipse, the code behaves correctly. The only wrong stuff is the following part of code does never retrieve the "failureMessage" attribute from the Captcha's component, how can i solve this too ? It is always null.

String summary = (String) component.getAttributes().get("failureMessage");

So, how can i solve the Bean validation problem ?<br>
And how can i retrieve correctly the attribute 'failureMessage' in my Validator ?

I've tried lot's of stuffs, and now i rely on you.<br>
Thanks in advance for helping.

PS : i'm currently using TomEE 1.5+ , Java6.