Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:59:41+00:00 2026-06-17T16:59:41+00:00

i have a composite component (a captcha actually) which i use into a h:form.

  • 0

i have a composite component (a captcha actually) which i use into a h:form.
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
ATTENTION: cannot validate component with empty value: captcha:captchaText

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

<!DOCTYPE html>
<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">
<h:body>

  <composite:interface>
    <composite:attribute name="id" type="java.lang.String" />
    <composite:attribute name="imageWidth" type="java.lang.Integer" />
    <composite:attribute name="imageHeight" type="java.lang.Integer" />
    <composite:attribute name="imageClass" type="java.lang.String" />
    <composite:attribute name="inputClass" type="java.lang.String" default="" />
    <composite:attribute name="placeholder" type="java.lang.String" default="" />
    <composite:attribute name="failureMessage" type="java.lang.String" default="Captcha validation failed" />

    <composite:editableValueHolder name="captchaText" />
  </composite:interface>

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

</h:body>
</html>

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;

    @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) && (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 here.

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

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

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

enter image description here

I prefer using the composite-component + validator + servlet
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 ?
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.
Thanks in advance for helping.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:59:42+00:00Added an answer on June 17, 2026 at 4:59 pm

    Looks like your inputText tag is missing the value attribute.
    The value attribute does the binding between the input and the bean.

    <h:inputText value="#{yourBean.yourValue" ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a composite component that contains a form with ajax. what i can't
I have the following composite component: <?xml version=1.0 encoding=UTF-8?> <ui:component xmlns=http://www.w3.org/1999/xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:ui=http://java.sun.com/jsf/facelets xmlns:c=http://java.sun.com/jsp/jstl/core
I have a composite component, which represents an item that will be stored in
I have the following Java Server Faces 2.0 composite component. Notice i am using
I'm trying to extend a LinearLayout to use as a composite component. I have
I use a composite component in a form, and I want to use an
I have a problem with a JSF composite which validates internal input fields. Following
I have to write a composite component that shows a login form and can
I have a Facelets Composite component that includes, among other things, a commandButton: <?xml
I'm creating a composite component in JSF 2..., inside it I have defined a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.