Why method annotated with @ModelAttribute could not pick up model attributes added through view
Why didn't the model.asMap()
in method annotated with @ModelAttribute
(i.e AM1
here) didn't return any model data but in the @RequestMapping
(i.e HM1
here) it does.
View:
<form:form action="SignupValidate.htm" modelAttribute="ma_CustomerTO">
CustName:<form:input path="CustName" />
CustSpouse:<form:input path="CustSpouse" />
I have submitted the form with fields values CustName
=abc CustSpouse
=xyz
Contoller:
@Controller
@RequestMapping("/Customer")
public class CustomerController
//-------------------------------------//
@ModelAttribute("ma_CustomerTO")
public CustomerTO AM1(Model model)
logger.debug(model.asMap()); //-----> does not print the model attributes from view???
CustomerTO customer=new CustomerTO();
customer.setCustName("Sheldon");
customer.setCustSpouse("Amy");
logger.debug(model.asMap());
return customer;
//-------------------------------------//
@RequestMapping("/SignupValidate.htm")
public ModelAndView HM1(Model model,@ModelAttribute("ma_CustomerTO") CustomerTO customer)
logger.debug(model.asMap());//-----> but this one prints
spring-mvc model modelattribute spring-form
add a comment |
Why didn't the model.asMap()
in method annotated with @ModelAttribute
(i.e AM1
here) didn't return any model data but in the @RequestMapping
(i.e HM1
here) it does.
View:
<form:form action="SignupValidate.htm" modelAttribute="ma_CustomerTO">
CustName:<form:input path="CustName" />
CustSpouse:<form:input path="CustSpouse" />
I have submitted the form with fields values CustName
=abc CustSpouse
=xyz
Contoller:
@Controller
@RequestMapping("/Customer")
public class CustomerController
//-------------------------------------//
@ModelAttribute("ma_CustomerTO")
public CustomerTO AM1(Model model)
logger.debug(model.asMap()); //-----> does not print the model attributes from view???
CustomerTO customer=new CustomerTO();
customer.setCustName("Sheldon");
customer.setCustSpouse("Amy");
logger.debug(model.asMap());
return customer;
//-------------------------------------//
@RequestMapping("/SignupValidate.htm")
public ModelAndView HM1(Model model,@ModelAttribute("ma_CustomerTO") CustomerTO customer)
logger.debug(model.asMap());//-----> but this one prints
spring-mvc model modelattribute spring-form
add a comment |
Why didn't the model.asMap()
in method annotated with @ModelAttribute
(i.e AM1
here) didn't return any model data but in the @RequestMapping
(i.e HM1
here) it does.
View:
<form:form action="SignupValidate.htm" modelAttribute="ma_CustomerTO">
CustName:<form:input path="CustName" />
CustSpouse:<form:input path="CustSpouse" />
I have submitted the form with fields values CustName
=abc CustSpouse
=xyz
Contoller:
@Controller
@RequestMapping("/Customer")
public class CustomerController
//-------------------------------------//
@ModelAttribute("ma_CustomerTO")
public CustomerTO AM1(Model model)
logger.debug(model.asMap()); //-----> does not print the model attributes from view???
CustomerTO customer=new CustomerTO();
customer.setCustName("Sheldon");
customer.setCustSpouse("Amy");
logger.debug(model.asMap());
return customer;
//-------------------------------------//
@RequestMapping("/SignupValidate.htm")
public ModelAndView HM1(Model model,@ModelAttribute("ma_CustomerTO") CustomerTO customer)
logger.debug(model.asMap());//-----> but this one prints
spring-mvc model modelattribute spring-form
Why didn't the model.asMap()
in method annotated with @ModelAttribute
(i.e AM1
here) didn't return any model data but in the @RequestMapping
(i.e HM1
here) it does.
View:
<form:form action="SignupValidate.htm" modelAttribute="ma_CustomerTO">
CustName:<form:input path="CustName" />
CustSpouse:<form:input path="CustSpouse" />
I have submitted the form with fields values CustName
=abc CustSpouse
=xyz
Contoller:
@Controller
@RequestMapping("/Customer")
public class CustomerController
//-------------------------------------//
@ModelAttribute("ma_CustomerTO")
public CustomerTO AM1(Model model)
logger.debug(model.asMap()); //-----> does not print the model attributes from view???
CustomerTO customer=new CustomerTO();
customer.setCustName("Sheldon");
customer.setCustSpouse("Amy");
logger.debug(model.asMap());
return customer;
//-------------------------------------//
@RequestMapping("/SignupValidate.htm")
public ModelAndView HM1(Model model,@ModelAttribute("ma_CustomerTO") CustomerTO customer)
logger.debug(model.asMap());//-----> but this one prints
spring-mvc model modelattribute spring-form
spring-mvc model modelattribute spring-form
edited Nov 13 '18 at 9:12
nguyentaijs
908
908
asked Oct 20 '18 at 11:16
sql_dummysql_dummy
237213
237213
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I have think possibly this should be happening. The @ModelAttribute
on method would not create a attribute for model until the end of the method.
add a comment |
Every method with @ModelAttribute
annotated will be called before receiving request from client in order to initialize model for your view. That's the use of method leveled @ModelAttribute
.
The model in your @ModelAttribute
method doesn't know about ma_CustomerTO
because it is called before your SignupValidate.htm
method is processed
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52905049%2fwhy-method-annotated-with-modelattribute-could-not-pick-up-model-attributes-add%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have think possibly this should be happening. The @ModelAttribute
on method would not create a attribute for model until the end of the method.
add a comment |
I have think possibly this should be happening. The @ModelAttribute
on method would not create a attribute for model until the end of the method.
add a comment |
I have think possibly this should be happening. The @ModelAttribute
on method would not create a attribute for model until the end of the method.
I have think possibly this should be happening. The @ModelAttribute
on method would not create a attribute for model until the end of the method.
answered Oct 20 '18 at 19:39
sql_dummysql_dummy
237213
237213
add a comment |
add a comment |
Every method with @ModelAttribute
annotated will be called before receiving request from client in order to initialize model for your view. That's the use of method leveled @ModelAttribute
.
The model in your @ModelAttribute
method doesn't know about ma_CustomerTO
because it is called before your SignupValidate.htm
method is processed
add a comment |
Every method with @ModelAttribute
annotated will be called before receiving request from client in order to initialize model for your view. That's the use of method leveled @ModelAttribute
.
The model in your @ModelAttribute
method doesn't know about ma_CustomerTO
because it is called before your SignupValidate.htm
method is processed
add a comment |
Every method with @ModelAttribute
annotated will be called before receiving request from client in order to initialize model for your view. That's the use of method leveled @ModelAttribute
.
The model in your @ModelAttribute
method doesn't know about ma_CustomerTO
because it is called before your SignupValidate.htm
method is processed
Every method with @ModelAttribute
annotated will be called before receiving request from client in order to initialize model for your view. That's the use of method leveled @ModelAttribute
.
The model in your @ModelAttribute
method doesn't know about ma_CustomerTO
because it is called before your SignupValidate.htm
method is processed
answered Nov 13 '18 at 8:18
nguyentaijsnguyentaijs
908
908
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52905049%2fwhy-method-annotated-with-modelattribute-could-not-pick-up-model-attributes-add%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown