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 7040609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:56:19+00:00 2026-05-28T01:56:19+00:00

With ModelAttribute annotation, we can feed many thing like listbox. Is it better to

  • 0

With ModelAttribute annotation, we can feed many thing like listbox.

Is it better to feed each lisbox with a different method in the controler or to use a form and have a list of object for every listbox?

  • 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-28T01:56:20+00:00Added an answer on May 28, 2026 at 1:56 am

    If the controller class is used for different requests where some have this listboxes and some not, (for example the Controller handles the show, create and update functions for an entity, where only the create and update pages have that list boxes) then popluating the model with the @ModelAttribute annotated method would mean, that this methods will be executed even if there values are not needed. — I my humble opinnion this would be bad.

    I hope I understand your question right, if not please add a example for each of the two choises you want to compare.

    @RequestMapping("/users")
    @Controller
    TheWayIPreferController() {
    
    @RequestMapping(params = "form", method = RequestMethod.GET)
    public ModelAndView createForm() {
      ModelMap uiModel = new ModelMap();
      uiModel.addAttribute("userCreateCommand", new UserCreateCommand());
      uiModel.addAttribute("securityRoles", this.securityRoleDao.readAll()));
      uiModel.addAttribute("salutations", this.salutationDao.readAll()));
      uiModel.addAttribute("locales", this.localeDao.readAll());
      return new ModelAndView("users/create", uiModel);
    }
    
    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView create(final @Valid UserCreateCommand userCreateCommand, final BindingResult bindingResult) {
    ...
    }
    
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ModelAndView show(@PathVariable("id") final User user) {
    ...
    }
    }
    

    instead of:

    @RequestMapping("/users")
    @Controller
    TheWayIDiscourageController(){
    
    
    @ModelAttribute("securityRoles")
    public List<SecurityRoles> getSecurityRoles(){
       return this.securityRoleDao.readAll();
    }
    
    @ModelAttribute("salutations")
    public List<SecurityRoles> getSalutations(){
       return this.salutationDao.readAll());
    }
    
    @ModelAttribute("locales")
    public List<SecurityRoles> getLocals(){
       return this.localeDao.readAll();
    }
    
    @RequestMapping(params = "form", method = RequestMethod.GET)
    public ModelAndView createForm() {
      return new ModelAndView("users/create", "userCreateCommand", new UserCreateCommand());
    }
    
    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView create(final @Valid UserCreateCommand userCreateCommand, final BindingResult bindingResult) {
    ...
    }
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ModelAndView show(@PathVariable("id") final User user) {
    ...
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

earlier I use Spring MVC and annotation @ModelAttribute. @Controller public class ArticleController { @ModelAttribute(articles)
I need help with understanding following example with @ModelAttribute from Spring documentation: (method populatePetTypes()
I'm currently using the @ModelAttribute annotation in my controllers to add reference data to
@ModelAttribute(user) @RequestMapping(value = /, method = RequestMethod.POST) public User saveUser( @RequestBody User user )
My controller has a method to return a form backing object: @ModelAttribute(userData) public UserData
Here's how my method looks like: @RequestMapping(value = /form, method = RequestMethod.POST) public String
I need some clarification about Spring 3.0 MVC and @ModelAttribute annotated method parameter. I
I'm having the strangest thing happening and I can't figure out why. The best
Using Spring/SpringMVC 3.0.5 I've defined a method in my controller like this: @RequestMapping(params =
I'm doing the spring 3 annotation based controller thing. Problem is, when it fails

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.