⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newvalidator.java

📁 精通Struts:基于MVC的java web车技与开发源程序(3)
💻 JAVA
字号:
package validate;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.RequestUtils;
import org.apache.struts.validator.Resources;

public class NewValidator implements Serializable {
  /**
   * A validate routine that ensures the value is either true or false.
   */
  public static boolean validateBoolean(Object bean,
                                    ValidatorAction va, Field field,
                                    ActionMessages errors,
                                    HttpServletRequest request) {

         String value = null;
    // The boolean value is stored as a String

    if (field.getProperty() != null && field.getProperty().length(  ) > 0){
      value = ValidatorUtils.getValueAsString(bean, field.getProperty(  ) );
    }

  
    if ( value==null || !(value.equalsIgnoreCase("true")||value.equalsIgnoreCase("false"))){
      errors.add( field.getKey(  ),
                  Resources.getActionMessage(request, va, field));
    }

    // Return true if the value was successfully converted, false otherwise
    return (errors.isEmpty(  ));

    }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -