Validation 如何使用<;sx:datetimepicker>;在struts2中?

Validation 如何使用<;sx:datetimepicker>;在struts2中?,validation,struts2,datetimepicker,Validation,Struts2,Datetimepicker,我在Jsp(struts2应用程序)中使用以下fromDate和toDate代码 其正在以指定格式生成日期。我想检查所选日期值,如果Todate小于Fromdate,则必须显示错误消息 有人能帮我解决这个问题吗。提前感谢。最直接的方法可能是实现Validateable,这可能是通过扩展ActionSupport最容易做到的。注:我在下面将“validFrom”改为“from”,将“validTo”改为“to” 然后在你的行动中你会写 //Not tested public void Vali

我在Jsp(struts2应用程序)中使用以下fromDate和toDate代码


其正在以指定格式生成日期。我想检查所选日期值,如果Todate小于Fromdate,则必须显示错误消息


有人能帮我解决这个问题吗。提前感谢。

最直接的方法可能是实现Validateable,这可能是通过扩展ActionSupport最容易做到的。注:我在下面将“validFrom”改为“from”,将“validTo”改为“to”

然后在你的行动中你会写

//Not tested
public void Validate(){
   //it is obvious that if one of these conditions is true the other will be as well
   //this is just to show the typical case of building up multiple field errors
   if (to.before(from)){
      addFieldError("to", getText("To date must be later than from date."));
   }
   if (from.after(to)){
      addFieldError("from", getText("From date must be before to date."));
   }
}
因为我喜欢选择简单的主题,你会发现你可以得到字段错误,以防你想要更多地控制错误消息的位置

有关验证的更多信息,请参阅:

//Not tested
public void Validate(){
   //it is obvious that if one of these conditions is true the other will be as well
   //this is just to show the typical case of building up multiple field errors
   if (to.before(from)){
      addFieldError("to", getText("To date must be later than from date."));
   }
   if (from.after(to)){
      addFieldError("from", getText("From date must be before to date."));
   }
}