Search in sources :

Example 6 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class RequriedValidator method validate.

public Validation validate(ValidatorConfigBean val, Context context) {
    Map<String, String> valError = new HashMap<String, String>();
    for (FieldConfigBean f : val.getField()) {
        String[] value = context.getQueryParamMap().get(f.getName());
        List<UploadFile> files = context.getUploadMap().get(f.getName());
        String mess = f.getMessage();
        if ((value == null || value.length == 0) && (files == null || files.isEmpty()))
            valError.put(f.getName(), mess);
        else {
            boolean isBlank = false;
            if (value != null)
                for (String v : value) {
                    if (v == null || v.trim().length() == 0) {
                        isBlank = true;
                        break;
                    }
                }
            if (!isBlank) {
                if (files != null)
                    for (UploadFile file : files) {
                        if (file == null || file.getFileName() == null || file.getFileName().trim().length() == 0 || file.getTmpFile() == null) {
                            isBlank = true;
                            break;
                        }
                    }
            }
            if (isBlank)
                valError.put(f.getName(), mess);
        }
        context.getRequest().setAttribute(f.getName(), value);
    }
    Validation validation = new Validation();
    if (!valError.isEmpty())
        validation.getErrors().put(val.getName(), valError);
    return validation;
}
Also used : Validation(org.eweb4j.mvc.action.Validation) UploadFile(org.eweb4j.mvc.upload.UploadFile) HashMap(java.util.HashMap) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 7 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class IDCardImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.ID_CARD.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.ID_CARD);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 8 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class IpImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.IP.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.IP);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 9 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class LengthImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.LENGTH.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.LENGTH);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    ParamConfigBean pcb = new ParamConfigBean();
    pcb.setName(Validators.MIN_LENGTH_PARAM);
    pcb.setValue(String.valueOf(ann.min()));
    fcb.getParam().add(pcb);
    ParamConfigBean pcb2 = new ParamConfigBean();
    pcb2.setName(Validators.MAX_LENGTH_PARAM);
    pcb2.setValue(String.valueOf(ann.max()));
    fcb.getParam().add(pcb2);
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 10 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class MyValidatorImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    Class<?> clazz = this.ann.clazz();
    String valName = clazz.getSimpleName();
    if (val == null || !valName.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(valName);
        val.setClazz(clazz.getName());
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    String[] params = ann.params();
    String[] values = ann.values();
    if (params.length > 0 && values.length > 0 && params.length == values.length) {
        for (int i = 0; i < params.length; i++) {
            ParamConfigBean pcb = new ParamConfigBean();
            pcb.setName(CommonUtil.parsePropValue(params[i]));
            pcb.setValue(CommonUtil.parsePropValue(values[i]));
            fcb.getParam().add(pcb);
        }
    }
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Aggregations

FieldConfigBean (org.eweb4j.mvc.config.bean.FieldConfigBean)32 ValidatorConfigBean (org.eweb4j.mvc.config.bean.ValidatorConfigBean)21 ParamConfigBean (org.eweb4j.mvc.config.bean.ParamConfigBean)19 HashMap (java.util.HashMap)11 Validation (org.eweb4j.mvc.action.Validation)11 ActionConfigBean (org.eweb4j.mvc.config.bean.ActionConfigBean)2 ResultConfigBean (org.eweb4j.mvc.config.bean.ResultConfigBean)2 UploadFile (org.eweb4j.mvc.upload.UploadFile)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 ConfigBean (org.eweb4j.config.bean.ConfigBean)1 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)1 IOCConfigBean (org.eweb4j.ioc.config.bean.IOCConfigBean)1 InterConfigBean (org.eweb4j.mvc.config.bean.InterConfigBean)1 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)1 DBInfoConfigBean (org.eweb4j.orm.dao.config.bean.DBInfoConfigBean)1