我有一个JSP页面,其中包含一些组件,如'从日期,到日期和一些预先填充的选择标准'和一个提取按钮。
如果我点击Extract按钮,它应该经过一些验证并返回actionErrors(如果有的话)。
但是,问题是在验证之后,如果失败则显示相应的错误消息,但预先填充的组件变空。
如何调用jsp的onload函数来预先填充所有组件?
验证参考方法:
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
request.setAttribute("REQ_SCREENNAME", ASConstant.VDB0018);
if (!request.getQueryString().startsWith("method=load")) {
if (mapping.getType().equals(VEHICLE_EMISSION_EVENT_REPORT_ACTION)) {
logger.debug("validate for ASVehicleEmissionEventReportingAction");
if ((this.getFromDate() == null) || (this.getFromDate().trim().length() == 0) || (this.getToDate() == null)
|| (this.getToDate().trim().length() == 0)) {
errors.add("nullDto", new ActionMessage("lable.VDB0011.VDBMESS020"));
}
else if ((this.getBrand() == null) || (this.getBrand().trim().length() == 0)) {
errors.add("nullDto", new ActionMessage("label.VDB0025.AS0001.tooltip"));
}
else if ((this.getStrEmissionStatus() == null) || (this.getStrEmissionStatus().length() == 0)) {
errors.add("nullDto", new ActionMessage("error.VDBMESS033.WFE0018E"));
}
else if ((this.getFromDate() != null) && (this.getFromDate().trim().length() > 0) && (this.getToDate() != null)
&& (this.getToDate().trim().length() >0))
{
SimpleDateFormat sdfmt1 = new SimpleDateFormat("dd/MM/yy");
Date d1;
try {
d1 = sdfmt1.parse(this.getToDate());
Date d2 =sdfmt1.parse(this.getFromDate());
int diffInDays = (int) ((d1.getTime() - d2.getTime()) / (1000 * 60 * 60 * 24));
String str_DaysVal = ASUtil.getPropertyValue("EmissionFix.EmissionReportDayDiff");
int i_Days =31;
if(str_DaysVal !=null && str_DaysVal.length() >0)
{
i_Days =Integer.parseInt(str_DaysVal);
}
if(diffInDays <0)
{
errors.add("nullDto", new ActionMessage("error.VDBMESS035.WFE0018E"));
}
else if(diffInDays >i_Days)
{
errors.add("nullDto", new ActionMessage("error.VDBMESS034.WFE0018E"));
}
} catch (ParseException e) {
logger.error(ASUtil.StackTraceToString(e));
}
}
}
}
return errors;
}
}