title: JSF 2 - composite-component - Bean validation fails due to component with empty value
body: <p>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.  </p>
  
  <blockquote>
    <p>16 janv. 2013 10:02:06 javax.faces.validator.BeanValidator validate<br>
    ATTENTION: cannot validate component with empty value: captcha:captchaText</p>
  </blockquote>
  
  <p>Here is the xhtml code of the captcha's composite-component</p>
  
  <pre><code>&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;h:body&gt;
  
    &lt;composite:interface&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;/composite:interface&gt;
  
    &lt;composite:implementation&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:inputText&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;
    &lt;/composite:implementation&gt;
  
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the Captcha's JSF Validator code.</p>
  
  <pre><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;
  
      @FacesValidator(CaptchaValidator.VALIDATOR_ID)
      public class CaptchaValidator implements Validator {
  
      public static final String VALIDATOR_ID = "captchaValidator";
  
      @Override
      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()
              .get(CaptchaServlet.CAPTCHA_KEY);
  
          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));
          }
      }
  
  }
  </code></pre>
  
  <p>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>.</p>
  
  <p>here is basically how i used the composite-component in my form. (This is not my real use case btw)</p>
  
  <pre><code>&lt;h:form&gt;
      &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;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>The form is rendered like this (with French localization) :</p>
  
  <p><img src="https://i.stack.imgur.com/wsrdV.png" alt="enter image description here"></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>String summary = (String) component.getAttributes().get("failureMessage");
  </code></pre>
  
  <p>So, how can i solve the Bean validation problem ?<br>
  And how can i retrieve correctly the attribute 'failureMessage' in my Validator ?</p>
  
  <p>I've tried lot's of stuffs, and now i rely on you.<br>
  Thanks in advance for helping.</p>
  
  <p>PS : i'm currently using TomEE 1.5+ , Java6.</p>