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

  • Home
  • SEARCH
  • 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 6832773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:53:58+00:00 2026-05-26T22:53:58+00:00

I need some clarification about Spring 3.0 MVC and @ModelAttribute annotated method parameter. I

  • 0

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 = RequestMethod.GET)
 public ModelAndView foo() {

               // do something
 }

@RequestMapping(method = RequestMethod.POST)
public ModelAndView bar(
        @ModelAttribute("barCommand") SomeObject obj) {

                    // do sometihng with obj and data sent from the form
}


}

and on my home.jsp i have a form like this one which sends his data to the RequestMethod.POST method of MyController

<form:form  action="home"  commandName="barCommband">

</form:form

Now if i try to access home.jsp i get this Exception:

java.lang.IllegalStateException:
Neither BindingResult nor plain target object for bean name 'barCommand' available as  request attribute

To resolve this i found that i need to add the

@ModelAttribute("barCommand") SomeObject obj 

parameter to the Request.GET method of MyController, even if i won’t use obj in that method. And for example if add another form to home.jsp with a different commandName like this:

<form:form  action="home/doSomething"  commandName="anotherCommand">

</form:form

i also have to add that parameter on the RequestMethod.GET, which will now look like:

@RequestMapping(method = RequestMethod.GET)
 public ModelAndView foo( @ModelAttribute("barCommand") SomeObject obj1,
  @ModelAttribute("anotherCommand") AnotherObj obj2) {

               // do something
 }

or i get the same exception. What i’m asking is if this is a normal Spring 3 MVC behaviour or if i’m doing something wrong. And why do i need to put all the @ModelAttribute parameters on the RequestMethod.GET method?

Thanks in advance for you help

Stefano

  • 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-26T22:53:58+00:00Added an answer on May 26, 2026 at 10:53 pm

    Here is the spring mvc reference. Looked through it briefly and found 2 approaches:

    1. @InitBinder
    2. @ModelAttribute(“bean_name”) with method.

    You may use first to customize data binding and, thus, create command objects on-the-fly. Second allows you to annotate method with it and prepopulate model attributes with this name:

    @ModelAttribute("bean_name")
    public Collection<PetType> populatePetTypes() {
        return this.clinic.getPetTypes();
    } 
    

    I hope it will populate model attributes with name ‘bean_name’ if it is null.

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

Sidebar

Related Questions

I just have a small question that I would like some clarification about, if
I need some clarification. I have a Reportwriter dll that uses Crystal Reports. It
Need some help about with Memcache. I have created a class and want to
I'm in need of some clarification. I've been reading about REST, and building RESTful
I need some clarification about the behaviour of svn switch. I'm using SVN version
I've read several threads about this topic and need some clarification on a few
I just need some clarification on variables A normal variable has 2 parts to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded

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.