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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:26:51+00:00 2026-05-18T11:26:51+00:00

OS: Windows vista, Framework: Spring (latest), JQuery (latest), Hibernate (latest). I have a domain

  • 0

OS: Windows vista, Framework: Spring (latest), JQuery (latest), Hibernate (latest).

I have a domain class with primary key as long id.

public class domain{
    private long id;
    ....
}

My Controller definition:

    @RequestMapping("/domainJqgridData/save")
public @ResponseBody String saveJqgridData(DomainClass domainclass) throws Exception {  
    return "Saved successfully!";
}

When the JSP form is submitted to add a new DomainClass record, the Spring controller tries to automatically bind the request parameters to domain class. It throws a BindException as follows:

Request processing failed; nested exception is org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object ‘domain’ on field ‘id’: rejected value [_empty]; codes [typeMismatch.domainclass.id,typeMismatch.id,typeMismatch.long,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [domainclass.id,id]; arguments []; default message [id]]; default message [Failed to convert property value of type ‘java.lang.String’ to required type ‘long’ for property ‘id’; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "_empty" from type ‘java.lang.String’ to type ‘long’; nested exception is java.lang.NumberFormatException: For input string: "_empty"]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)

As I am adding a new DomainClass record, the id field is passed as null by the JSP form. Spring converts the null id to empty string value for binding purpose and throws the error. I browsed the net and found that I can register custom editors for such purpose. I changed the DomainClass primitive type definition long id, to Long id and tried to bind a custom editor as follows.

Controller class:
@InitBinder
public void initBinder(WebDataBinder binder) { 
    binder.registerCustomEditor(Long.class, new CustomPrimitiveFormat(Long.class, true));
    binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
}

My custom primitive editor class is as follows:

public class CustomPrimitiveFormat extends CustomNumberEditor{

public CustomPrimitiveFormat(Class numberClass, boolean allowEmpty)
    throws IllegalArgumentException {
    super(numberClass, allowEmpty);
    // TODO Auto-generated constructor stub
}

public void setValue(Object value){
    System.out.println("Entered CustomPrimitiveFormat setValue");
    if (value == null) {
        super.setValue(null);
        return;
    }
    if (value.getClass().equals(String.class)){
        if (StringUtils.isEmpty((String)value)){
            super.setValue(null);
        }
    }
}

public void setAsText(Object value){
    System.out.println("Entered CustomPrimitiveFormat setAsText");
    if (value == null) {
        super.setValue(null);
        return;
    }
    if (value.getClass().equals(String.class)){
        if (StringUtils.isEmpty((String)value)){
            super.setValue(null);
        }
    }
}

}

I still receive the BindingException. Could not find any link that would guide me through how to overcome Spring BindException when adding a new Domain class record. I would like my primary key to remain primitive type, instead of using the Number object type.

Thanks in advance for your help.

  • 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-18T11:26:51+00:00Added an answer on May 18, 2026 at 11:26 am

    As you can see in the error message, jqGrid uses _empty as an id of the new record (also see here), so you need to change your PropertyEditor to convert _empty to null.

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

Sidebar

Related Questions

OS: Windows Vista, Framework: Jqgrid (latest), Spring (latest), JQuery (latest) I am using Jqgrid
I have Windows Vista MCML app, and I need to figure out the current
Windows 7 and Vista have the .NET 2.0/3.5 language runtime installed, so whatever you
I'm using Windows 7 (all latest updates installed), and currently have DirectX 11 installed
Can I have a Windows Vista/7 gadget where the app is loaded from a
I have installed MinGW in Windows Vista, so I can use gcc but it
What I have installed... Windows Vista Ultimate Service Pack 1 Visual Studio 2008 Service
I have one windows application built using C# and .net framework 2.0 and its
Under Windows Vista, when I check whether my current user account is in Administrators
Until Windows Vista, ATI and nVidia supported a feature called horizontal span, which combined

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.