why does struts reset my form after failed validation?

前端 未结 3 591
死守一世寂寞
死守一世寂寞 2021-01-25 14:04

I am using the validation framework with Struts 1.1.When validation fails, the entire form is reset.

After much time scouring the net, I have gathered:

  1. Wh
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 14:31

    @Override
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    
        //If Clear button click will set date as today and clear all other value
        //If Insert, update with validation as failure than not clear all value on the form, but only clear that wrong when validation (means skipp all value as true on the form and only clear value wrong)
        String actionName = request.getParameter("method");
        if(actionName!=null){
            if (actionName.equals(Enums.ActionName.CLEAR.getActionName())) {
                Date date = new Date();
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                this.setPublicationDay(dateFormat.format(date));
            }
            else{
                request.setAttribute("book", this);
            }
        }
    
        super.reset(mapping, request);
    }
    

提交回复
热议问题