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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:45:33+00:00 2026-05-25T12:45:33+00:00

Parts of the (Java, Spring-mvc, JSP) Form input is checked by Javascript. The rest

  • 0

Parts of the (Java, Spring-mvc, JSP) Form input is checked by Javascript. The rest is done by a custom Validator.
The problem is when the Javascript validation is prevented, such an error may be printed:

Failed to convert property value of type java.lang.String to required type java.lang.Long for property xxx; nested exception is java.lang.NumberFormatException: For input string: "x"

Is there a better way to deal with the conversion itself. When the Java-validator runs it already encounters the conversion error – or is there a possibility to check before that?


edit: the code of the Binder within the Controller..

@InitBinder
public void initBinder(WebDataBinder binder) {
   SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
   dateFormat.setLenient(false);

   binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
   binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, true));
}

but its really just standard functionality (org.springframework.beans.propertyeditors.CustomNumberEditor) and I thought there has to be a simple solution, since it seems like a common thing to have a Long Object backing some imput field and trying to get no exception out of it (or catching that one)..

  • 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-25T12:45:33+00:00Added an answer on May 25, 2026 at 12:45 pm

    if someone’s interested .. the code of the custom Binder that worked in the end follows..

      // prevent alphanumeric/special chars in numeric string (for backing field of type Long)
      binder.registerCustomEditor(Long.class, new CustomNumberEditor(Long.class, true) {
         @Override
         public void setAsText(String value) {
            if (value != null && !value.isEmpty() && CustomValidator.isNumeric(value)) {
               super.setAsText(value);
            } else {
               super.setAsText(null);
            }
         }
      });
    

    although, you still have to adjust your validation method so that it makes sense with text that was entered, got removed, and was changed to null!

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

Sidebar

Related Questions

How do I get whole and fractional parts from double in JSP/Java ? If
In Spring MVC I can access my beans in JSP using JstlView's exposedContextBeanNames (or
I am trying to complete the Spring MVC tutorial at: http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html My problem is
I'm trying to add a simple REST service to a default Spring MVC Template
I'm currently building a Spring MVC application. I was looking to use JSP pages
I have been learning java spring hibernate MVC for 3 months and got pretty
I have a Google App Engine app using Java and Spring MVC 3.0. A
I am learning both AJAX and the Java Servlet API (well, Spring MVC, which
I'm porting parts of Java project to C# and came across this constant Constant.NamespaceSpecNS.
Many parts of the Java API work differently depending on platform defaults, for example,

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.