SpringMVC - Displaying objects in form:options

Hi I am completely from a mobile background, so Spring is new to me, I have currently I have a form called as BusinessForm here are the contents

public class BusinessForm 
 private String selectedBusinessId; //getters and setters included
 private List businessNameList; //getters and setters included - list of Business class Objects
  private List businessIdList; //getters and setters included  - lisy of Business class Objects
//Business class defined below 

Here is my Controller

public class HomeController{
    @RequestMapping(value = "/showHome", method = RequestMethod.GET)
    public ModelAndView showHome()
         //Init BusinessForm class, its defined above...
         //set values of businessNameList...
         //set values of businessIdList...
         BusinessForm businessForm = new BusinessForm();
         return ModelAndView("MyView","businessForm", businessForm)

Here is my view (I will show only the form to avoid showing everyhting else)


<form:form action="blah" method="post" modelAttribute="businessForm">
<form:select path="selectedBusinessId">
<form:option value="">Select ID</form:option>
<form:options items="${businessForm.businessIdList}" item/>

So right now my businessIdList seen is above code for form:options items attribute is a list of "Business" objects and the Business objects have private variables businessName and businessId with getter and setters

public class Business
  private String businessId; //with getters and setter 
  private String businessName; //with getters and setters 

so in the form above once I open the drop down its actually showing me a list, but that String is nothing but the toString() function of Business class. So my drop down items are looking like com.xxx.Business@c291000. Wihtout overriding toString() of Business class, how do I make my form to display the actual businessId on the drop down of the form list. The reason is I want to get another form:select and display another list of businessName. Please help. Thanks.


You need to change your

<form:select path="selectedBusinessId">
    <form:option value="">Select ID</form:option>
    <form:options items="${businessForm.businessIdList}" item/>


<form:select path="selectedBusinessId">
    <form:option value="">Select ID</form:option>
    <form:options items="${businessForm.businessIdList}" itemValue="businessId" itemLabel="businessName" />

Need Your Help

the use of __stdcall and __cdecl in Windows CE DLLs

c++ dll windows-ce calling-convention

I have a Visual Studio 2008 C++03 application for Windows CE 6.0 x86. I'm having an issue where invoking a function from a DLL is causing an access violation exception, but only in debug mode.

Ruby on Rails Debug Question

ruby-on-rails debugging ruby-on-rails-3

Hello guys I have this video tutorial on Ruby on Rails and I see that the guy has a bottom script debug, in the browser window. The problem is, I have only one part of that video tutorial (that par...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.