Web程序从Struts向Stripes框架的移植

http://tech.ddvip.com   2006年11月20日    社区交流

本文详细介绍Web程序从Struts向Stripes框架的移植

public class UpdateEmployeeActionBean implements ActionBean {
private ActionBeanContext context;
private Employee employee;
public ActionBeanContext getContext() {
return context;
}
public void setContext(ActionBeanContext context) {
this.context = context;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public Employee getEmployee() {
return this.employee;
}
@DefaultHandler
public Resolution update() {
EmployeeDAOService.updateEmployee(employee);
return new ForwardResolution("/employees/updateEmployee.jsp");
}
}

  在大多数情况中,我能够嵌入我的域对象的一个副本作为我的Stripes ActionBean类的一个属性并且仅包括涉及把该对象移入/移出我的持久层的代码部分。我把所有表单处理都交给了Struts Action来实现,包括初始化配置、把表单强制转换成适当的类以及从域对象中来回转换数据(约30%的代码是在大多数Action类中实现的)。在Stripes中并不需要这样。

  简言之,把域对象作为你的ActionBean类的一个属性嵌入,为该类提供了getter和setter方法。总之,所有有趣的地方(包括列表)都在HTML视图的表单中体现出来。

  所有我对表单的操作也都可以通过查询串参数方式来实现。我仅把这些参数作为我的ActionBean的一个属性,而如果它们是请求的一部分的话,可以把它们自动地复制到相应的域中。

  (四) 校验

  与表单或标签移植相比,把Struts校验移植到Stripes要求更多的工作。在我的应用程序中,我必须在Stripes ActionBean类内部使用Java 5.0注解重写在validation.xml文件中的校验配置。Stripes还为你提供一种良好的基于类型的校验。当用户输入错误值时,不需要用户进行任何配置,Stripes就可以把HTML表单返回给他们(例如,在一个数字或日期域中的字符)。表单能够被自动返回并带有一条向用户友好显示的消息,最后出错域被高亮显示。

来源:天极开发    作者:朱先忠    责编:豆豆技术应用

正在加载评论...