嗨,我完全是一个移动背景,所以春天对我来说是新的,我现在有一个名为BusinessForm的表单,这里是内容
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
}这是我的控制器
@Controller
public class HomeController{
@RequestMapping(value = "/showHome", method = RequestMethod.GET)
@ExceptionHandler({CutsomException.class})
public ModelAndView showHome()
{
//Init BusinessForm class, its defined above...
//set values of businessNameList...
//set values of businessIdList...
BusinessForm businessForm = new BusinessForm();
businessForm.setBusinessNameList(....);
businessForm.setBusinessIdList(....);
return ModelAndView("MyView","businessForm", businessForm)
}
}这是我的观点(我只会显示表格,以避免显示其他人)
MyView.jsp
<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/>
</form:select>
</form:form>现在我看到的是表单的代码:options items属性是" Business“对象的列表,业务对象具有私有变量businessName和businessId以及getter和setters。
public class Business
{
private String businessId; //with getters and setter
private String businessName; //with getters and setters
}因此,在上面的表单中,一旦我打开下拉列表,它实际上向我显示了一个列表,但是该字符串只不过是Business的toString()函数。所以我的下拉项目看起来像com.xxx.Business@c291000。Wihtout覆盖toString()的Business,如何使我的表单在表单列表下拉列表中显示实际的businessId。原因是我想获得另一个表单:选择并显示另一个businessName列表。请帮帮忙。谢谢。
发布于 2014-09-30 00:55:13
你需要改变你的
<form:select path="selectedBusinessId">
<form:option value="">Select ID</form:option>
<form:options items="${businessForm.businessIdList}" item/>
</form:select>至
<form:select path="selectedBusinessId">
<form:option value="">Select ID</form:option>
<form:options items="${businessForm.businessIdList}" itemValue="businessId" itemLabel="businessName" />
</form:select>https://stackoverflow.com/questions/26110239
复制相似问题