Questions tagged [modelattribute]
315 questions
433
votes
14 answers
What is @ModelAttribute in Spring MVC?
What is the purpose and usage of @ModelAttribute in Spring MVC?

Mohammad Adnan
- 6,527
- 6
- 29
- 47
100
votes
5 answers
Difference between modelAttribute and commandName attributes in form tag in spring?
In Spring 3, I have seen two different attribute in form tag in jsp
in this the attribute modelAttribute is the name of the form object whose properties are used to populate the form. And I used it…

Pulkit
- 3,953
- 6
- 31
- 55
44
votes
10 answers
How to pass model attributes from one Spring MVC controller to another controller?
I am redirecting from a controller to another controller. But I also need to pass model attributes to the second controller.
I don't want to put the model in session.
Please help.

ajm
- 12,863
- 58
- 163
- 234
29
votes
3 answers
Spring MVC Multiple ModelAttribute On the Same Form
I have a form with two ModelAttributes one is citizens and the other is punishment. The two objects are separated by jquery tabs. I am having problems in getting the items on the form to display properly some are being displayed and some are not. I…

devdar
- 5,564
- 28
- 100
- 153
16
votes
7 answers
Spring : binding object with and without @ModelAttribute
I am new in Spring and registering a user.I did like this.
@RequestMapping("/register")
public String register(@ModelAttribute User user,BindingResult result){
if(!result.hasErrors()){
userSerive.register(user);
}
…

TheCurious
- 593
- 1
- 4
- 29
16
votes
2 answers
Spring MVC @ModelAttribute method
Question about Spring MVC @ModelAttribute methods, Setting model attributes in a controller @RequestMapping method verses setting attribute individually with @ModelAttribute methods, which one is considered better and is more used?
From design point…

Kamal Kishore
- 193
- 1
- 1
- 8
13
votes
1 answer
How to pass th:object values from html to controller
How to pass thymeleaf(th:object) values to controller.
HTML:
SearchPersonController:
@RequestMapping(value = "/modify/{pid}", method = RequestMethod.GET)
…

Java_User
- 475
- 2
- 11
- 30
13
votes
2 answers
Dynamic form and data binding with Spring MVC
In my Spring MVC application I need to implement a dynamic questionnaire form: I have N questions and for each I have 3 options.
So in my page I'll have something like this:
| Question 1 | 1 | 2 | 3 |
| Question 2 | 1 | 2…

davioooh
- 23,742
- 39
- 159
- 250
12
votes
1 answer
What is the difference between @ModelAttribute, model.addAttribute in spring?
i am new Spring learner.i'm really confused about what is the difference between two concept:
@ModelAttribute
model.addAttribute
in below there are two "user" value.Are these same thing?Why should I use like this?
Thank you…

ssmm
- 171
- 1
- 1
- 10
10
votes
2 answers
Where exactly is a model object created in Spring MVC?
After going through some tutorials and initial document reading from the docs.spring.org reference I understood that it is created in the controller of a POJO class created by the developer.
But while reading this I came across the paragraph…

JAVA
- 524
- 11
- 23
9
votes
1 answer
Spring 3 -- accessing Model values in JSP
I have a JSP where I am trying to print out values from my Model, but nothing appears in the place where I refer to those values. Here is the controller method where I set the values.
@RequestMapping(value = "/poll1", method =…
user636859
8
votes
2 answers
Spring MVC ModelAttribute Fields Are Null Instead of Form Input Values
I'm trying to make a form that will post a CardRequestResource:
public class CardRequestResource extends ResourceSupport{
private Long cardRequestId;
private String deliveryMethod;
private String address;
private boolean…

AForsberg
- 1,074
- 2
- 13
- 25
7
votes
2 answers
Could Spring MVC call @ModelAttribute after @RequestMapping?
I have a controller like this:
@Controller
public class HomeController {
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(@RequestParam("user") User user, ModelMap model){
…

marstone
- 686
- 1
- 10
- 23
6
votes
1 answer
Spring form ModelAttribute field validation to avoid 400 Bad Request Error
I've got an ArticleFormModel containing data sent by normal html form which is injected by Spring using @ModelAttribute annotation, i.e.
@RequestMapping(value="edit", method=RequestMethod.POST)
public ModelAndView acceptEdit(@ModelAttribute…

Mateusz
- 3,038
- 4
- 27
- 41
6
votes
3 answers
Spring MVC - difference between HttpSession.setAttribute and model.addObject
I am trying to learn Spring MVC recently. It seems that i did not understand well the functionalities of @ModelAttribute annotation and HttpSession.
@SessionAttributes({"shoppingCart", "count"})
public class ItemController…

akcasoy
- 6,497
- 13
- 56
- 100