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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:20:19+00:00 2026-06-08T18:20:19+00:00

I have a problem with the binding of a form input text to a

  • 0

I have a problem with the binding of a form input text to a Integer field of the bean to which the form is binded. If I write a wrong number in the input text (eg: “12b”) I have a Binding Exception. So, I set a @InitBinder in my controller in this way:

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Integer.class, new CustomIntegerBinder());
    }

Where CustomIntegerBinder is implemented as follows:

    public class CustomIntegerBinder extends PropertyEditorSupport {

        @Override
        public void setAsText(String text) throws IllegalArgumentException {
            try {
                setValue(Integer.parseInt(text));
            } catch (Exception e) {
                //I WANT TO ADD ERROR TO THE ERROR LIST!
            }
        }

        @Override
        public String getAsText() {
            return getValue().toString();
        }
    }        

My question is: how could I succeed in adding a message error to the errors list, so that a conversion error would not cause a crasch of the application, but a message to be printed in the “errors” tag in the jsp?

Thank you!

  • 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-08T18:20:20+00:00Added an answer on June 8, 2026 at 6:20 pm

    The setAsText method should throw an IllegalArgumentException (as the method signature indicates) if the value can’t be set from text.

    If you throw the IllegalArgumentException from your catch then Spring should add the error for you.

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

Sidebar

Related Questions

I have a problem in binding JSON data to KENDO Pie Chart. I have
I have a problem with my Binding to a ListBox Control. Actually i have
I have a problem with the binding of the below parameter. The connection works
We have an interesting problem with WCF binding and streaming transfer mode that we
As the title says, I have a problem with binding to a change in
I am using asp.net mvc 2.0(default binding model) and I have this problem. I
I'm having some problems with bean initialization. I have an edit form to update
Since including <mvc:annotation-driven/> I have experienced a problem when binding the selections of multi-select
I'm having problems binding on a form with multiple models being submitted. I have
I have a form which I want to post to ensure the page refreshes

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.