How to call jsp page onload function when action form returns errors?

405 views Asked by At

I have a JSP page which contains some components like ' From Date, To Date and Some selection criteria which will pre-populated' and an Extract button.

If I click on Extract button, It should go through some validations and returns actionErrors if any found.

But, the problem is after validation, if it fails it is showing appropriate error message but pre-populated components are getting empty.

How to call jsp's onload function to pre populate all the components?

validate method for reference:

  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;
}

}

jsp page for reference

0

There are 0 answers