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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:39:54+00:00 2026-05-22T18:39:54+00:00

My spring web application is using ajax with spring, and it based in general

  • 0

My spring web application is using ajax with spring, and it based in general on the demo application provided by spring:

https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk/
(Additional info : http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/)

On the client-side I have a form (JSP):

<form:form modelAttribute="createLevel" action="createLevel" method="post">  
    <div class="form-item">  

    <form:label id="nameLabel" for="name" path="name" cssErrorClass="error">Level Name</form:label><br/>
     <form:input path="name" /><form:errors path="name" />
    </div>
    <div class="form-item">
    <input type="submit" value="Submit">  
    </div>  
</form:form>

I submit the form to the server by the following js method:

$("#createLevel").submit(function() {
        var level = $(this).serializeObject();
        $.postJSON("create.do", level, function(data) {
            alert(data);
        });
        return false;               
    });

On the server-side I have a validation as it shown below:

public final class LevelDto extends AbstractDto implements Serializable {
    private static final long serialVersionUID = 1L;

    private int id;

    @NotNull
    @Size(min = 2, max = 30)
    @LevelExistsConstraint(message = "Level with provided name is exists")
    private String name;
    // set; get;
}

And Controller

   @RequestMapping(value = "/admin/create.do", method = RequestMethod.POST)
    public @ResponseBody
Map<String, ? extends Object> createLevel(@RequestBody LevelDto level,
        HttpServletResponse response) {
    //JSR-303 
    Set<ConstraintViolation<LevelDto>> failures = validator.validate(level);

    if (!failures.isEmpty()) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return validationMessages(failures);

    } else {

        return Collections.singletonMap("id", 10);

    }
}

When I submit incorrect data to the server I see that all things are going on correctly – my validator is processing data, and the client is receiving an error response; moreover, in the response content I see the following:

{"name":"size must be between 2 and 30"}

My problem is that I do not know how to bind received error message correctly. Obviously, I can do it by js, but I thought that Spring is binding all error messages automatically to the view.

Any help is really appreciated.

-Cyril

  • 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-22T18:39:55+00:00Added an answer on May 22, 2026 at 6:39 pm

    create AjaxResponse class as a container of form field, status, and description.

    class AjaxResponse {
        model; //form attribute
        status;  // OK or ERROR
        description; // message description such as error message
    }
    

    You can loop the failure validation result, generate List of AjaxResponse based on Failure Validation Result in JSON Format as a response of your controller action.

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

Sidebar

Related Questions

i just completed a web based chat application based on ajax/php. But the problem
We have a Spring web application created using Spring MVC 3.0 In the same
I'm trying to send data from a client application using jQuery to a REST
In my asp .net form, I refresh a control using Ajax through the AjaxPro
Currently, I am working on a web application that uses draw2d library to draw
Ive got a question to Spring Security 3.0.5. When using Spring Security to secure
I am building a REST based API (Read only) for accessing services of my
I have a web service that wish to call, and I want to pass
I'm trying to create an AJAX control and I'm unable to see the property
I'm trying to get ASP.Net to cache the response of a web service request

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.