【发布时间】:2014-05-25 19:55:09
【问题描述】:
考虑以下示例中的 struts 2 应用程序。这是一个显示网格的页面,用户可以将 SAME 网格导出为 PDF。
我们开发了一个包含两个动作的类,一个动作以 JSON 格式返回网格,另一个将 SAME 网格导出为 PDF。
代码结构如下:
定义了两个不同的动作图/ShowGrid和/ExportGrid
@Action (name="ShowGrid") // Result will be set to JSON
@validation ( @Required (..... // Validation Rules for fromDate toDate etc
public String showGrid(){
gird = serviceFacade.getGrid(fromDate,toDate);
return SUCCESS;
}
@Action (name="ExportGrid" ) //Result will be set as stream
@validation ( @Required ..... // Validation Rules for fromDate toDate etc
public String exportGrid(){
grid = serviceFacade.getGrid(fromDate,toDate);
inputStream = convertGridToStream(grid); // By using jasper report or other tools
return SUCCESS;
}
如您所见,上述方法有很多共同的结构,
- 验证重复(在我的用例中,验证规则很多)
- 调用服务方法重复
有什么办法可以避免吗?!
【问题讨论】:
标签: java configuration struts2 annotations struts-validation