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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:12:43+00:00 2026-05-26T15:12:43+00:00

I have an object. public class MyObject { …. @Column(name = a_number) @NotNull @NumberFormat(style

  • 0

I have an object.

public class MyObject
{
   ....
   @Column(name = "a_number") @NotNull @NumberFormat(style = Style.NUMBER) @Min(1)
   private Integer aNumber;
   ...
   //getters and setters
}

In my controller I have @Valid annotation on my object being posted. I do have validation working on all my other fields in the class (their all Strings) except this number. If I enter a number from my form it works fine and if I violate the @Min(1) it also gives me the correct validation error. My problem however is that if you enter a string instead of a number it throw a NumberFormatException.

I’ve seen many examples of Integer and validation but no one accounts for if you enter a string into the form being posted. Do I need to do the validation else where? Javascript? I would like a solution that falls in line with the rest of spring validation so I could use this in other classes. I would just like an error stating it must be numeric. Also I tried using the @Pattern annotation but apparently thats just for strings.

Suggestions?

  • 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-26T15:12:43+00:00Added an answer on May 26, 2026 at 3:12 pm

    You can add the following to your file which controls your error messages (these are the generic ones it looks for in the case of a type mismatch:

    typeMismatch.commandObjectName.aNumber=You have entered an invalid number for ...
    typeMismatch.aNumber=You have entered an invalid number for ...
    typeMismatch.java.lang.Integer=You have input a non-numeric value into a field expecting a number...
    typeMismatch=You have entered incorrect data on this page.  Please fix (Catches all not found)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code a bit like this public class MyObject { private bool IsValidDay(ref
I have an object - @Entity public class myObject{ public string fieldA; public string
I have an object - @Entity public class myObject{ public MySecondObject objA; public MySecondObject
Let's say I have an object MyObject that looks like this: public class MyObject
I have an object like this: public class MyObject{ public int Prop1 {get;set;} }
I have the following business object: public class MyObject { // Some public properties
I have this object : public class MyObject { public int Id { get;
I have a collection of this object : public Class MyObject() { public int
I have a simple QObject-derived object: class MyObject : public QObject { Q_OBJECT public:
I have an object like this: class MyObject { public string Object.Prop1 { get;

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.