This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi all, I am having an ajax controller. This controller will receive post data. I am validating the post data and then if it has some errors I am sending the errors as a json object.
The error messages, codes are in the BindingResult. So I created a new class called JsonValidatedResponse. In this class I am extracting the error codes and fields and adding them to appropriate lists. Then sending the marshaled object to client.
My doubt is should if I want to autowire this JsonValidatedResponse object, which scope should I use? Request scope or singleton scope? However I am not creating any session to have session scope.
As I see request scope is what I need I think so. Can anyone please suggest me? This is how my JsonValidatedResponse looks likeThis is what I am doing in the controller
This is in essence a DTO (data transfer object). Its sole purpose is to pass information from your controller to your view. Typically I would not make these type of objects Spring beans. In any object though it is good practice to make your fields private unless there is a good reason not to (currently they are package private).