Struts 2 自定义验证器问题

发布于 2024-09-12 16:45:57 字数 188 浏览 4 评论 0原文

我有一个用于 CRUD 操作的操作和 3 个自定义验证器。

其中两个验证器工作正常,但另一个则无法正常工作。它正确处理验证,并返回适当的错误,但如果没有错误,工作流就不会完成,它永远不会到达操作。就好像它被困在验证器中一样。日志文件中没有错误。如果我删除验证器,就会达到操作。

我不确定我做错了什么,如果有任何帮助,我将不胜感激。

I have an Action for CRUD operations and 3 custom validators.

Two of the validators work correctly, but the other one does not. It handles correctly the validation, and returns the appropriate errors, but if there are no errors, the workflow does not complete, it never reaches the Action. It is as if it is stuck in the validator. There are no errors in the log file. If I remove the validator, the Action is reached.

I am not sure what I am doing wrong, and I would appreciate any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

王权女流氓 2024-09-19 16:45:57
package com.timesheet.validator;

import java.util.Map;

import com.timesheet.action.TimeSheetAction;


import com.timesheet.util.TimeSheetClient;

import com.timesheet.util.TimeSheetHolder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.ValidatorSupport;

public class TimeSheetSubmission extends ValidatorSupport{


 @Override
 public void validate(Object arg0) throws ValidationException {
  // TODO Auto-generated method stub

  Map session = ActionContext.getContext().getSession();
  TimeSheetAction act = (TimeSheetAction)ActionContext.getContext().getActionInvocation().getAction();
  TimeSheetClient client = act.getClient();

  if(session.get("holder") != null){
   TimeSheetHolder holder = (TimeSheetHolder)session.get("holder");

       if(!(excessTime(holder) && lessTime(holder))){

        client.cleanUp();
     addActionError(arg0);
     return;
    }else{

     client.cleanUp();
     return;
    }

  }
 }
 public boolean lessTime(TimeSheetHolder holder){
  boolean done = true;
  TimeSheetHolder.Day day = holder.dailyHours();
  switch(day){

   case Mon: setMessageKey("timeSheet.mon.less.hours"); 
        done = false;  
      break;
   case Tue: done = false;  
      setMessageKey("timeSheet.tue.less.hours"); 
      break;
   case Wed: done = false;  
      setMessageKey("timeSheet.wed.less.hours"); 
      break;
   case Thu: done = false;  
      setMessageKey("timeSheet.thu.less.hours"); 
      break;
   case Fri: done = false;  
      setMessageKey("timeSheet.fri.less.hours"); 
      break;
   default:  break;
   }
  return done;
 }
 public boolean excessTime(TimeSheetHolder holder){
  boolean done = true;
  TimeSheetHolder.Day day = holder.moreTime();
  switch(day){

   case Mon: setMessageKey("timeSheet.mon.excess.hours"); 
        done = false;  
      break;
   case Tue: done = false;  
      setMessageKey("timeSheet.tue.excess.hours"); 
      break;
   case Wed: done = false;  
      setMessageKey("timeSheet.wed.excess.hours"); 
      break;
   case Thu: done = false;  
      setMessageKey("timeSheet.thu.excess.hours"); 
      break;
   case Fri: done = false;  
      setMessageKey("timeSheet.fri.excess.hours"); 
      break;
   default:  break;
   }
  return done;
 }

}
package com.timesheet.validator;

import java.util.Map;

import com.timesheet.action.TimeSheetAction;


import com.timesheet.util.TimeSheetClient;

import com.timesheet.util.TimeSheetHolder;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.ValidatorSupport;

public class TimeSheetSubmission extends ValidatorSupport{


 @Override
 public void validate(Object arg0) throws ValidationException {
  // TODO Auto-generated method stub

  Map session = ActionContext.getContext().getSession();
  TimeSheetAction act = (TimeSheetAction)ActionContext.getContext().getActionInvocation().getAction();
  TimeSheetClient client = act.getClient();

  if(session.get("holder") != null){
   TimeSheetHolder holder = (TimeSheetHolder)session.get("holder");

       if(!(excessTime(holder) && lessTime(holder))){

        client.cleanUp();
     addActionError(arg0);
     return;
    }else{

     client.cleanUp();
     return;
    }

  }
 }
 public boolean lessTime(TimeSheetHolder holder){
  boolean done = true;
  TimeSheetHolder.Day day = holder.dailyHours();
  switch(day){

   case Mon: setMessageKey("timeSheet.mon.less.hours"); 
        done = false;  
      break;
   case Tue: done = false;  
      setMessageKey("timeSheet.tue.less.hours"); 
      break;
   case Wed: done = false;  
      setMessageKey("timeSheet.wed.less.hours"); 
      break;
   case Thu: done = false;  
      setMessageKey("timeSheet.thu.less.hours"); 
      break;
   case Fri: done = false;  
      setMessageKey("timeSheet.fri.less.hours"); 
      break;
   default:  break;
   }
  return done;
 }
 public boolean excessTime(TimeSheetHolder holder){
  boolean done = true;
  TimeSheetHolder.Day day = holder.moreTime();
  switch(day){

   case Mon: setMessageKey("timeSheet.mon.excess.hours"); 
        done = false;  
      break;
   case Tue: done = false;  
      setMessageKey("timeSheet.tue.excess.hours"); 
      break;
   case Wed: done = false;  
      setMessageKey("timeSheet.wed.excess.hours"); 
      break;
   case Thu: done = false;  
      setMessageKey("timeSheet.thu.excess.hours"); 
      break;
   case Fri: done = false;  
      setMessageKey("timeSheet.fri.excess.hours"); 
      break;
   default:  break;
   }
  return done;
 }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文