2014-09-29 17 views
0

您好我来自一个移动的背景是完全,所以春天是新的给我,我有我目前有一个被称为 BusinessForm形式这里的内容用SpringMVC - 显示对象的形式:选择

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) 
    } 
} 

这是我的观点(我将只显示形式,以避免显示everyhting人)

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> 

所以现在看到我businessIdList为如上形式的代码:选择项目属性是“企业”对象和业务对象有私有变量BUSINESSNAME和企业版扩展的getter和setter

列表
public class Business 
{ 
    private String businessId; //with getters and setter 
    private String businessName; //with getters and setters 
} 

所以在上面的表格中,我打开下拉列表,其中实际向我展示了一个列表,但该字符串不过是Business类的toString()函数。所以我的下拉菜单看起来像[email protected]Wihtout覆盖Business类的toString(),如何使表单在​​窗体列表的下拉列表中显示实际的businessId。原因是我想获得另一种形式:选择并显示businessName的另一个列表。请帮忙。谢谢。

+0

标题可能是误导性的,如果有人了解情况...... wpuld不胜感激,如果你可以编辑标题。谢谢 ! – uLYsseus 2014-09-29 23:40:45

回答

1

你需要改变你的

<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> 
+0

+1了解并让我找到正确的方向 – uLYsseus 2014-10-01 18:25:03