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

  • SEARCH
  • Home
  • 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 9112337
In Process

The Archive Base Latest Questions

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

A quick background : I have put a captcha using the primefaces custom component

  • 0

A quick background : I have put a captcha using the primefaces custom component on my website. People in charge don’t like it as it is too difficult to use and clients are/were complaining. I decided I wanted to create a simple component (ie: 4 + 9 = and user inputs the answer) to avoid a bit of spam. No need to have an image display the question, just using simple text. This got me looking into custom components and composite component ( from this article and this one ).

Now, the question is not so much about a makeshift basic “captcha style validation”. It’s more about a composite component and backing bean combo.

What I would do is create a backing bean in this style :

<cc:interface>

    <cc:attribute name="label" />
<!-- edited -->
    <cc:attribute name="required" />
<cc:attribute name="ident" />

</cc:interface>


<cc:implementation>

    <h:panelGrid columns="3">
        <h:outputText value="#{captcha.text}"/>
        <h:inputText id="#{cc.attrs.ident}" value="#{captcha.entered}" validator="#{captcha.validate}" required="#{cc.attrs.required eq 'true'}" label="#{cc.attrs.label}" />
        <h:message for="captchaAnswer" />
    </h:panelGrid>

    <h:inputHidden value="#{captcha.value}" />

</cc:implementation>

And then I’d like to use this component in this manner :

<h:form>
    ...
    <tr>
        <td>
            <my:captcha label="Captcha" ident="captcha" required="true"/> <!-- added after suggested comment -->
            <br/>
            <h:message for="captcha" class="error"/>
        </td>
    </tr>
    <tr>
        <td colspan="3" class="center">
            <h:commandButton class="button" value="#{msg['contact.label.send']}" action="#{contact.send}" >
        </h:commandButton>
        </td>
    </tr>
    ...
</h:form>

How can I make sure that on submit I can check that my {#captcha.entered} value is the required value and if not returns a validation message on the form and prevents it from being submitted?

captcha backing bean would be simple and have values : text, answer, and, entered and a simple function to check if answer == entered.

EDIT : (Attempt #1)
custom validator would look as follow

public void validate(FacesContext context, UIComponent toValidate, Object value) {

    System.out.println("validating");

    String input = (String) value;

    //check to see if input is an integer
    //if not we know right away that the value is not good
    if(StringUtils.isNumeric(input)) {
        //if the input is numeric, convert to an integer
        int intValue = new Integer(input).intValue();
        if (intValue != answer) {
            ((UIInput) toValidate).setValid(false);

            FacesMessage message = new FacesMessage("Not a match!!");
            context.addMessage(toValidate.getClientId(context), message);
        }
    }
}

In this instance the validator does not even get called and I don’t get an error message.

Edit #2

After a bit of working and hints from comments I got this working. To get the h:message working I needed to add the attribute ident instead of id. If not I had to reference it as so : <h:message for="captcha:captcha" /> which was not the desired outcome.

  • 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-17T03:42:43+00:00Added an answer on June 17, 2026 at 3:42 am

    The primary issue with this question was that I couldn’t get a reference.

    By adding the attribute ident instead of id I got this to work. Please refer to edit #2 in question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick background, I am using Netbeans to develop this (I don't have much experience
Quick background: I'm programming in PHP, I have a domain model with a separate
Quick background for those interested, I have a master detail table(options date), about 20
Here's a quick background on what I'm trying to do. I have a contact
Quick background: I have a string which contains references to other pages. The pages
Real quick background : We have a PDFMaker (HTMLDoc) that converts html into a
Hello everyone: I have set a custom background for my navigation bar, it's a
I want to put on a web page background. I have a background of
So the quick background is that I have a page listing a set of
Quick background of what I have going on. UIMapView loads and shows a single

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.