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 911205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:09:55+00:00 2026-05-15T17:09:55+00:00

The problem I’m having is that my Bean Validation isn’t working as I would

  • 0

The problem I’m having is that my Bean Validation isn’t working as I would expect.

I have a Session Scoped Managed Bean with a name field that is bound to an h:inputText. The name must be entered, and have a minimum length of 1 character, and a maximum length of 5 characters. I expect that when I enter the name into the textbox, it will be validated accordingly by the backing bean, and if it fails, then it would display the corresponding error messages.

However, this is not the case. The validations are always failing, even if I enter a valid case in the inputText (e.g. “abc”). On debugging the application, it seems that the getName() accessor is always called, and the setter is never reached. Am I doing something wrong? I assume the validator uses the accessor to validate, but the problem is that the setter never gets a chance to update the value of the name… I must be missing something.

Below is the Managed Bean:

@ManagedBean
@SessionScoped
public class James implements Serializable {

  public James() {
    super();
   }

  private String name;

  @NotNull
  @Min(value = 1)
  @Max(value = 5)
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

Below is the fragment of the JSF xhtml. I tried a few different variations with separate forms, but the first option is the one I would assume to work (I think it’s equivalent to the third option, but tried just in case 🙂 )

<h:messages/>
<h:form>
  <h:inputText id="jamesName" value="#{james.name}"/>
  <h:message for="jamesName"/>
  <h:commandButton value="submit"/>
</h:form>
<h:form>
  <h:inputText id="jamesName" value="#{james.name}" immediate="true"/>
  <h:message for="jamesName"/>
  <h:commandButton value="submit"/>
</h:form>
<h:form>
  <h:inputText id="jamesName" value="#{james.name}">
    <f:validateBean />
  </h:inputText>
  <h:message for="jamesName"/>
  <h:commandButton value="submit"/>
</h:form>

I’m using JSF 2.0.2-FCS with Hibernate Entity Manager 3.3.2.GA and Hibernate Validator 4.0.2.GA (below are the relevant parts from my Maven POM), running in Tomcat 6.0.20 on Windows XP Pro Service Pack 3 (32-bit).

<dependency>
  <groupId>javax.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>2.0.2-FCS</version>
</dependency>
<dependency>
  <groupId>javax.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>2.0.2-FCS</version>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.1</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>3.3.2.GA</version>
</dependency>
<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-validator</artifactId>
  <version>4.0.2.GA</version>
</dependency>
  • 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-05-15T17:09:56+00:00Added an answer on May 15, 2026 at 5:09 pm

    Your validation is working correctly. The problem is with your @Min and @Max annotations:

    @NotNull
    @Min(value = 1)
    @Max(value = 5)
    public String getName() {
        return name;
    }
    

    @Min and @Max are meant for numeric comparison. You wrote:

    The name must be entered, and have a minimum length of 1 character, and a maximum length of 5 characters

    You should use @Size annotation instead, as in:

    @NotNull
    @Size(min = 1, max = 5)
    public String getName() {
        return name;
    }
    

    The bean fields are not updated because the validation fails. Only after the validation succeeds will the bean get updated.

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

Sidebar

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.