1

こんにちは、私は完全にモバイルのバックグラウンドを持っているので、Spring は初めてです。現在、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>

したがって、現在表示されている businessIdList は form:options のコードの上にあります。項目属性は「ビジネス」オブジェクトのリストであり、ビジネス オブジェクトには getter と setter を持つプライベート変数 businessName と businessId があります。

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

上記のフォームでドロップダウンを開くと、実際にはリストが表示されますが、その文字列は Business クラスの toString() 関数に他なりません。したがって、ドロップダウン項目は com.xxx.Business@c291000 のようになります。Business クラスの toString() をオーバーライド せずに、フォーム リストのドロップダウンに実際の businessId を表示するようにフォームを作成するにはどうすればよいですか。理由は、別のフォームを取得したいからです。businessName の別のリストを選択して表示します。助けてください。ありがとう。

4

1 に答える 1

3

変更する必要があります

<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>
于 2014-09-30T00:55:13.270 に答える