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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:14:04+00:00 2026-05-22T23:14:04+00:00

In my controller: @Controller public class UserController { @RequestMapping(value=/admin/user/id/{id}/update, method=RequestMethod.GET) public ModelAndView updateUserHandler(@ModelAttribute(userForm) UserForm

  • 0

In my controller:

@Controller
public class UserController {

    @RequestMapping(value="/admin/user/id/{id}/update", method=RequestMethod.GET)
    public ModelAndView updateUserHandler(@ModelAttribute("userForm") UserForm userForm, @PathVariable String id) {

        Map<String, Object> model = new HashMap<String, Object>();
        userForm.setCompanyName("The Selected Company");
        model.put("userForm", userForm);

        List<String> companyNames = new ArrayList<String>();
        companyNames.add("First Company Name");
        companyNames.add("The Selected Company");
        companyNames.add("Last Company Name");

        model.put("companyNames", companyNames);

        Map<String, Map<String, Object>> modelForView = new HashMap<String, Map<String, Object>>();
        modelForView.put("vars", model);

        return new ModelAndView("/admin/user/update", modelForView);
    }
}

The select form field in my view:

<form:form method="post" action="/admin/user/update.html" modelAttribute="userForm">
<form:select path="companyName" id="companyName" items="${vars.companyNames}" itemValue="id" itemLabel="companyName" />
</form:form>

It was my understanding that the form backing bean would be mapped based upon the modelAttribute attribute in the form. I’m obviously missing something here.

  • 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-22T23:14:05+00:00Added an answer on May 22, 2026 at 11:14 pm

    It appears the issue was not related to my setup. The problem was that the itemValue was set to the company id property, while the comparison was being done to the company name property on my form backing bean. So the two were not equal, and therefore, no item was set to selected.

    The above code works just fine, and setting the value in the userForm for a particular property will set that value as selected in select form fields so long as the value of one of the items in the items collection is equal to the form value. I changed my form field to look like this, which pulls the companyName instead of the id.

    <form:form method="post" action="/admin/user/update.html" modelAttribute="userForm">
    <form:select path="companyName" id="companyName" items="${vars.companyNames}" itemValue="companyName" itemLabel="companyName" />
    </form:form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring controller defined like this: @Controller @RequestMapping(/user) class UserController { ...
I have a controller with an action method as follows: public class InventoryController :
m developing rest api by zf. this is my user controller. <?php class UserController
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
Given the following classes and controller action method: public School { public Int32 ID
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
Model public class PdfPage { public IEnumerable<PdfPhoto> Photos { get; set; } } public
Which is more correct? This (with the @Autowired annotation on the method)? @Controller public
I have a controller in which I have a GET method display a form
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.