Search in sources :

Example 11 with FieldConfigBean

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

the class PhoneImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.PHONE.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.PHONE);
    }
    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 12 with FieldConfigBean

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

the class RegexImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.REGEX.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.REGEX);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    ParamConfigBean pcb = new ParamConfigBean();
    pcb.setName(Validators.REGEX_PARAM);
    pcb.setValue(CommonUtil.parsePropValue(ann.pattern()));
    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)

Example 13 with FieldConfigBean

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

the class TestValidator method validate.

public Validation validate(ValidatorConfigBean val, Context context) {
    Map<String, String> errMap = new HashMap<String, String>();
    for (FieldConfigBean fcb : val.getField()) {
        // 比如我现在验证 "name"参数值不能出现 "中国" 字眼
        String key = fcb.getName();
        // 这个是封装了request请求传过来的参数map
        String value = context.getQueryParamMap().get(key)[0];
        if (value.indexOf("中国") != -1)
            errMap.put(key, fcb.getMessage());
    }
    Validation validation = new Validation();
    validation.getErrors().put(val.getName(), errMap);
    return validation;
}
Also used : Validation(org.eweb4j.mvc.action.Validation) HashMap(java.util.HashMap) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 14 with FieldConfigBean

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

the class EmailImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.EMAIL.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.EMAIL);
    }
    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 15 with FieldConfigBean

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

the class UploadImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.UPLOAD.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.UPLOAD);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    ParamConfigBean suffix = new ParamConfigBean();
    suffix.setName(Validators.UPLOAD_SUFFIX);
    StringBuilder sb = new StringBuilder();
    for (String s : ann.suffix()) {
        if (sb.length() > 0)
            sb.append(",");
        sb.append(CommonUtil.parsePropValue(s));
    }
    suffix.setValue(sb.toString());
    fcb.getParam().add(suffix);
    ParamConfigBean suffixMsg = new ParamConfigBean();
    suffixMsg.setName(Validators.UPLOAD_SUFFIX_MSG);
    suffixMsg.setValue(CommonUtil.parsePropValue(ann.msg().suffix()));
    fcb.getParam().add(suffixMsg);
    ParamConfigBean maxFileSize = new ParamConfigBean();
    maxFileSize.setName(Validators.UPLOAD_MAX_FILE_SIZE);
    maxFileSize.setValue(CommonUtil.parsePropValue(ann.maxFileSize()));
    fcb.getParam().add(maxFileSize);
    ParamConfigBean maxFileSizeMsg = new ParamConfigBean();
    maxFileSizeMsg.setName(Validators.UPLOAD_MAX_FILE_SIZE_MSG);
    maxFileSizeMsg.setValue(CommonUtil.parsePropValue(ann.msg().maxFileSize()));
    fcb.getParam().add(maxFileSizeMsg);
    ParamConfigBean maxMemorySize = new ParamConfigBean();
    maxMemorySize.setName(Validators.UPLOAD_MAX_MEMORY_SIZE);
    maxMemorySize.setValue(CommonUtil.parsePropValue(ann.maxMemorySize()));
    fcb.getParam().add(maxMemorySize);
    ParamConfigBean maxMemorySizeMsg = new ParamConfigBean();
    maxMemorySizeMsg.setName(Validators.UPLOAD_MAX_MEMORY_SIZE_MSG);
    maxMemorySizeMsg.setValue(CommonUtil.parsePropValue(ann.msg().maxMemorySize()));
    fcb.getParam().add(maxMemorySizeMsg);
    ParamConfigBean maxRequestSize = new ParamConfigBean();
    maxRequestSize.setName(Validators.UPLOAD_MAX_REQ_SIZE);
    maxRequestSize.setValue(CommonUtil.parsePropValue(ann.maxRequestSize()));
    fcb.getParam().add(maxRequestSize);
    ParamConfigBean maxRequestSizeMsg = new ParamConfigBean();
    maxRequestSizeMsg.setName(Validators.UPLOAD_MAX_REQ_SIZE_MSG);
    maxRequestSizeMsg.setValue(CommonUtil.parsePropValue(ann.msg().maxRequestSize()));
    fcb.getParam().add(maxRequestSizeMsg);
    ParamConfigBean tmpDir = new ParamConfigBean();
    tmpDir.setName(Validators.UPLOAD_TMP_DIR);
    tmpDir.setValue(CommonUtil.parsePropValue(ann.tmpDir()));
    fcb.getParam().add(tmpDir);
    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