Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7705587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:54:02+00:00 2026-05-31T23:54:02+00:00

Auto-binding of request params seems like default behaviour, but I can’t find a lot

  • 0

Auto-binding of request params seems like default behaviour, but I can’t find a lot of documentation on it. Here is my example:

<form:form modelAttribute="test" action="testsubmit.do" method="POST">
  Name: <form:input path="name" />
  Nested Name: <form:input path="test.nestedName"/> 
<input type="submit"/>


public class Test {
    public String name;
    public String name2;
    public TestNested test;
    ...

public class TestNested {
    public String nestedName;
    ...

Now with my mapping:

@RequestMapping(value = "/testsubmit")
public String testSubmit(Test test){
    ...

The test object is binding the form values including the nested value. This seems to me like expected behavior, but I am a bit confused by the @ModelAttribute annotation and its use with respect to objects specified as mapped method parameters.

15.3.2.8 Providing a link to data from the model with @ModelAttribute says:

When you place it on a method parameter, @ModelAttribute maps a model attribute to the specific, annotated method parameter (see the processSubmit() method below). This is how the controller gets a reference to the object holding the data entered in the form.

When I bind the object test to the form on load, I set a value to name2.

@RequestMapping(value = "/test")
public String test(Model model) {       
    Test test = new Test();
    test.setName2("test name2");
    model.addAttribute("test", test);
    return "test";
}

This doesn’t get passed through on the submit method when I annotate the test parameter with @ModelAttribute("test"):

@RequestMapping(value = "/testsubmit")
public String testSubmit(@ModelAttribute("test") Test test) {
    ...

This is expected to me as name2 was not specified as a form field/request param, but it doesn’t help me understand the point of the @ModelAttribute("test") usage. Can anyone shed some light on this for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:54:03+00:00Added an answer on May 31, 2026 at 11:54 pm

    @ModelAttribute just lets you specify a different name/key for your object in the model. If you don’t use it, Spring will automatically assign a name based on the object’s class, e.g. “test” in the case of your “Test” class. With @ModelAttribute you could change the name/key of your object in the model to, for example, “whatever” by specifying “@ModelAttribute(“whatever”)”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using auto implemnted properies like public string MyProperty { get; set; } This
<GroupBox Header={Binding Path=FilterGroupName} Height =Auto IsEnabled={Binding IsSelected} IsVisible={Binding Selected} /> I get an error
Writing a lot of these for a listview. Seems a little bloated to first
I'm learning binding in WPF. I can get binding to work when 1) the
I guess the auto-value is set after parsed by the binding. Binding code: Width={Binding
I have a DataGrid bound to a DomainDataSource: <sdk:DataGrid AutoGenerateColumns=False Height=Auto ItemsSource={Binding ElementName=mailboxDomainDataSource, Path=Data,Mode=TwoWay}
I avoided to ask this question, but the ListBox's selected index can no be
I need to implement auto-capitalization inside of a Telerik RadEditor control on an ASPX
I am developing an auto-builder that will run a series of steps in our
We have an auto-complete list that's populated when an you send an email to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.