具有多态性的Spring formBackingObject

时间:2015-05-11 14:34:03

标签: java spring spring-mvc

我在当前的Spring应用程序中设计向导模块时遇到问题。使用选择一种报告然后填写必要的数据来创建报告

整个向导过程仅包含两个步骤:

Step1: a view with a single drop-down menu, allow user to choose
       report type, click next

Step2: based on the report user has chosen, the second view should 
       show up whatever fields required for user to fill in. Once 
       user check finish, The application generates the report.

显然,第二步包括多态性。理想的选择是

public class Report{
    private String type; // for the first step of wizard
    private IReport report; // for the second step of wizard
    ........
}

接口IReport可以只是一个空接口。然后,每个特定报告可能具有特定字段

public class MicroReport implements IReport{
    private String microUnit;
    private Date startDate;
    private Date dueDate;
    .....
}

public class MacroReport implements IReport{
    private List<String> macroUnit;
    private int level;
    private Date generatedDate;
    .....
}

我希望在每个JSTL中,html对象可以命名为:

microReport.jspx:
<input name="microreport.report.microUnit" value="..."></input>


macroReport.jspx:
<input name="macroreport.report.macroUnit[0]" value="..."></input>
<input name="macroreport.report.macroUnit[1]" value="..."></input>
<input name="macroreport.report.macroUnit[2]" value="..."></input>
.....

但是在这种情况下,如何定义Spring formBackingObject?任何建议都表示赞赏。

0 个答案:

没有答案