我有一个 JSP 页面,其中包含一些组件,例如“从日期、到日期和一些将预先填充的选择标准”和一个提取按钮。
如果我单击提取按钮,它应该经过一些验证并返回 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;
}
}