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

📄 hasdatavalidator.java

📁 这个是使用java开发的一个平台
💻 JAVA
字号:
package com.exp.web.util.validator;

import com.exp.fcl.xml.EXPXMLNode;
import com.exp.web.util.FormBean;

/**
 * 在给定的属性列表中必须有至少有一个不为空
 * 
 * @author zhanghf
 * @version 1.0
 */
public class HasDataValidator extends BaseValidator {
    protected int count = 1;

    protected void initConfig(EXPXMLNode validator) {
        String temp = validator.getAttributeValue("count");
        if (!temp.equals("")) {
            this.count = Integer.valueOf(temp).intValue();
        }
    }

    public boolean checkValid(FormBean formBean) {
        int realCount = 0;
        String[] attrs = getTargets();
        for (int i = 0; i < attrs.length; i++) {
            String temp = attrs[i].trim();
            if (!temp.equals("")) {
                temp = formBean.getString(temp);
                temp = temp.trim();
                if (!temp.equals("")) {
                    realCount++;
                }
            }
        }
        return realCount >= this.count;
    }

    private String[] getTargets() {
        String[] attrs = this.getTarget().split(",");
        return attrs;
    }

    public boolean isEmptyJump() {
        return false;
    }

    protected String genCheckCondition() {
        String[] targets = this.getTargets();
        int len = targets.length;
        StringBuffer buf = new StringBuffer();
        buf.append(" var nCount = 0;");
        for (int i = 0; i < len; i++) {
            buf.append("\nif (");
            String temp = targets[i];
            buf.append(this.formName);
            buf.append(".");
            buf.append(temp);
            buf.append(".value ='')\n{");
            buf.append("\n\t nCount++;\n}");
        }
        buf.append("\nif( nCount < ");
        buf.append(this.count);
        buf.append(")\n{");
        buf.append("\n\talert('");
        buf.append(this.getMessage());
        buf.append("');\n\t");
        buf.append(this.formName);
        buf.append(".");
        buf.append(targets[0]);
        buf.append(".focus();");
        buf.append("\n\t return false;\n}");
        return buf.toString();
    }

    protected void checkHandle(StringBuffer buf) {

    }
}

⌨️ 快捷键说明

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