Spring MVC form:errors using Ajax?

Not really, no. The form:error tag does its magic when the page is first generated server-side. If you're not re-generating the page serverside, because you used ajax, none of that is going to run.

The Errors object itself isn't really returnable all the way back to the client. You could serialize it to JSON I suppose, but there's an awful lot of stuff in there that you don't need. Plus of course it usually only has codes, not actual messages, on it and needs the message source to look up the translations Bottom line, you'll need to send the errors manually and handle setting the error messages yourself in javascript when you get back the ajax response.

Not really, no. The form:error tag does its magic when the page is first generated server-side. If you're not re-generating the page serverside, because you used ajax, none of that is going to run.

The Errors object itself isn't really returnable all the way back to the client. You could serialize it to JSON I suppose, but there's an awful lot of stuff in there that you don't need. Plus of course it usually only has codes, not actual messages, on it and needs the message source to look up the translations.

Bottom line, you'll need to send the errors manually and handle setting the error messages yourself in javascript when you get back the ajax response.

You can't, since tags like are evaluated server-side and embed error messages/elements in the HTML content of the HTTP response. Since an AJAX request to the server typically returns XML or JSON to a response (and not HTML), which is then parsed by client-side JavaScript, there is no point at which Spring can bind to the request/form and add error messages to the content.

I have used quite a lot of AJAX when submitting forms in Spring. Basically what I have done is that I have created a form. Jsp file which I then return from the AJAX call.

Since the AJAX will return the whole form with all the form tags available, I get the full benefit of server side validation. So, if I have a page that contains a form, I could, for example, have a div that acts as the form container Normal form here ... And when I submit the form, I could load the form. Jsp by using jQuery, for example, $('#myform').

Submit(function() { $('#form-container'). Load('ajax/somehandler'); }); So, all you have to do is to return the form. Jsp from the controller with all the normal bindings as you would have with non-AJAX approach as well.Do you get the idea?

Yes. I'll try that. Thanks!

– Dan May 24 at 21:01.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions