Questions tagged [modelattribute]

315 questions
6
votes
1 answer

When is a @ModelAttribute annotated method called precisely?

The following is a simple Spring form controller to handle 'add item' user requests: @Controller @RequestMapping("/addItem.htm") public class AddItemFormController { @Autowired ItemService itemService; @RequestMapping(method =…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
5
votes
1 answer

Can ModelAttribute be primitive?

I am having a strange problem with ModelAttribute in Spring MVC 3.0. When I deploy the app at localhost, it works fine. But when I deploy the app on a remote server, it fails everytime user access a specific action, with the errors: ERROR:…
Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
5
votes
3 answers

ModelAttribute returns null values in controller in Spring MVC

Ok, its time to seek help; I am sending a (shopping) Cart ModelAttribute to my jsp, allowing the user to edit the quantity, when the Model is POST to the controller the fields are null except the editable (quantity) field. I have researched for days…
brad12s
  • 419
  • 2
  • 7
  • 17
5
votes
2 answers

spring interface as @ModelAttribute param

I have UsersController with method: @RequestMapping(value={"/new"}, method=RequestMethod.GET) public String showCreationForm(@ModelAttribute User user){ return "user_registration_form"; } which displays registration form. I want to keep…
Bladositto
  • 293
  • 3
  • 14
4
votes
3 answers

@ModelAttribute and @SessionAttribute in Spring

As Spring Specification said, @ModelAttribute will executed before the mapping handler and @SessionAttribute will keep the model attribute in session. Consider below scenario: form bean is created after the controller is called and is set as session…
user1105456
  • 41
  • 1
  • 3
4
votes
1 answer

How do I map properties of a ModelAttribute?

I have a request mapped like @RequestMapping(value = "/path", method = RequestMethod.POST) public ModelAndView createNewItem(@ModelAttribute PostRequest request) and the PostRequest has some properties like e.g. userName…
rurouni
  • 2,315
  • 1
  • 19
  • 27
4
votes
4 answers

How to reset a @ModelAttribute in Spring MVC after it has been processed in the controller?

I have defined a @ModelAttribute("mymodel") @ModelAttribute("mymodel") MyModel mymodel() { MyModel mymodel = new MyModel(); return mymodel; } @RequestMapping(value = "/save", method = RequestMethod.POST) public final void…
HHWilchevsky
  • 41
  • 1
  • 1
  • 2
4
votes
2 answers

When we must use @ModelAttribute, and how it works

Hello I have question about @ModelAttribute annotation. As i understand, we use @ModelAttribute in method arguments to get data from the model. But it's quite hard to understand clearly when and how its used. (Code samples are from Spring in…
James Lar
  • 87
  • 1
  • 6
4
votes
3 answers

Why do we need jackson databind?

I am new in Spring MVC. My question is, why do we need jackson databind? Because We can receive the Request Params by @ModelAttribute and requests through http PUT or POST by @RequestBody. I can't find a reason why we need jackson databind to…
Niaz Ahsan
  • 351
  • 1
  • 7
  • 21
4
votes
3 answers

spring form jsp binding reference bean

I was trying to bind POJO using spring form tag library. After binding reference class bean variables, I am getting "Bad Request Error- Http Status 400". If I remove binding of reference class, My form is submitted successfully and values are also…
Ankit
  • 2,126
  • 4
  • 33
  • 53
4
votes
2 answers

yii2 rules not applying to non-db attributes?

I would like to upload multiple files at once. I have a model: class KakiKingModel extends ActiveRecord { public $uploadedFiles; public function rules() { return [ [['uploadedFiles'], 'file', 'extensions' => 'txt',…
user2511599
  • 796
  • 1
  • 13
  • 38
4
votes
1 answer

How to access model attribute in jQuery

I need to pass a model attribute from controller to HTML. My application is using HTML5, thymeleaf & springboot. I am using the below code snippet: $(document).ready(function() { var modelAttributeValue = '${modelAttribute}'; } Code snippet…
Java_User
  • 475
  • 2
  • 11
  • 30
4
votes
1 answer

Spring MVC SessionAttributes with ModelAttribute usage

I am trying to learn Spring MVC recently. It seems that i did not understand well the functionality of @SessionAttributes and @ModelAttribute annotations. This is a part of my controller: @SessionAttributes({"shoppingCart", "count"}) public class…
akcasoy
  • 6,497
  • 13
  • 56
  • 100
4
votes
3 answers

MVC3 TextBoxFor vs. EditorFor - issues with each

I've looked around the web for a while, but can't find a good solution to my specific issue. I'm working on a MVC3 Razor app. I'm doing a bunch of stuff on the client side with jQuery as well so in this case I need my input fields to have html Id…
gilm0079
  • 595
  • 1
  • 4
  • 18
3
votes
1 answer

Java - Spring 3.0 MVC and @ModelAttribute

I need some clarification about Spring 3.0 MVC and @ModelAttribute annotated method parameter. I have a Controller which looks like this one: RequestMapping(value = "/home") @Controller public class MyController { @RequestMapping(method =…
ssstefano
  • 35
  • 1
  • 4
1
2
3
20 21