Пример #1
0
 /**
  * 使用弹出窗口显示验证信息
  *
  * @param ds
  */
 public void showValidateInOldStyle(Dataset ds) {
   Map<String, Object> validatorMap = validator(ds);
   if (validatorMap == null) {
     return;
   }
   validatorMap = dealValidator(validatorMap, ds);
   // 所有错误信息 key-fieldid value-errorMsg
   Map<String, String> error_fields_map =
       (Map<String, String>) validatorMap.get("error_fields_map");
   if (error_fields_map != null && !error_fields_map.isEmpty()) {
     // 错误类型序号
     int index = 1;
     StringBuffer allErrorMsg =
         new StringBuffer(Validator.getValidatorMsg(ValidatorType.saveFailure.ordinal()));
     // 分类错误信息
     Map<Integer, List<Field>> type_fields_map =
         (Map<Integer, List<Field>>) validatorMap.get("type_fields_map");
     if (type_fields_map != null && !type_fields_map.isEmpty()) {
       List<Field> list = null;
       ValidatorType[] types = ValidatorType.values();
       for (ValidatorType type : types) {
         list = type_fields_map.get(type.ordinal());
         if (list != null && list.size() > 0) {
           index =
               getFieldErrorMsgByErrorType(
                   allErrorMsg,
                   list,
                   index,
                   Validator.getValidatorMsg(ValidatorType.followingMsg.ordinal())
                       + Validator.getValidatorMsg(type.ordinal())
                       + ":");
         }
       }
     }
     // 自定义验证信息
     Map<String, List<Field>> formular_fields_map =
         (Map<String, List<Field>>) validatorMap.get("formular_fields_map");
     if (formular_fields_map != null && !formular_fields_map.isEmpty()) {
       List<Field> list = null;
       String key = null;
       Iterator<String> keys = formular_fields_map.keySet().iterator();
       while (keys.hasNext()) {
         key = keys.next();
         list = formular_fields_map.get(key);
         if (list != null && list.size() > 0) {
           index = getFieldErrorMsgByErrorType(allErrorMsg, list, index, key + ":");
         }
       }
     }
     if (index > 1) {
       throw new LuiRuntimeException(ds.getCaption() + allErrorMsg.toString());
     }
   }
 }
Пример #2
0
 /**
  * 处理验证结果
  *
  * @param validatorMap
  * @param ds
  * @return
  */
 private Map<String, Object> dealValidator(Map<String, Object> validatorMap, Dataset ds) {
   // field错误提示信息类型(平台默认验证) key-fieldId_rowIndex, value-errorType
   Map<String, Integer> errorTypeMap = (HashMap<String, Integer>) validatorMap.get("errorTypeMap");
   // field错误提示信息(自定义验证公式) key-fieldId_rowIndex, value-errorMsg
   Map<String, String> formularMsgMap =
       (HashMap<String, String>) validatorMap.get("formularMsgMap");
   if (!errorTypeMap.isEmpty() || !formularMsgMap.isEmpty()) {
     // field错误提示信息 key-fieldid_rowIndex, value-errorMsg
     Map<String, String> error_fields_map = new HashMap<String, String>();
     // 错误信息分类包含的field集合
     Map<Integer, List<Field>> type_fields_map = null;
     if (!errorTypeMap.isEmpty()) {
       type_fields_map = new HashMap<Integer, List<Field>>();
       List<Field> list = null;
       String key = null;
       String fieldId = null;
       Iterator<String> keys = errorTypeMap.keySet().iterator();
       while (keys.hasNext()) {
         // key-field_rowIndex
         key = keys.next();
         fieldId = key.substring(0, key.lastIndexOf("_"));
         // 当前错误信息分类包含的field集合
         list = type_fields_map.get(errorTypeMap.get(key));
         if (list == null) {
           list = new ArrayList<Field>();
         }
         boolean temp = true;
         if (ds.getField(fieldId).getSourceField()
             != null) { // 当前field包含sourcefield,list中移除sourcefield。
           for (Field f : list) {
             if (f.getId().equals(ds.getField(fieldId).getSourceField())) {
               list.remove(f);
               break;
             }
           }
         } else { // 当前field不包含sourcefield,判断当前field是否是list中某个field的sourcefield。
           for (Field f : list) {
             if (ds.getField(fieldId).getId().equals(f.getSourceField())) {
               temp = false;
               break;
             }
           }
         }
         if (temp) {
           list.add(ds.getField(fieldId));
           type_fields_map.put(errorTypeMap.get(key), list);
         }
         error_fields_map.put(key, Validator.getValidatorMsg(errorTypeMap.get(key)));
       }
     }
     // 自定义错误信息分类包含的field集合
     Map<String, List<Field>> formular_fields_map = null;
     if (!formularMsgMap.isEmpty()) {
       formular_fields_map = new HashMap<String, List<Field>>();
       List<Field> list = null;
       String key = null;
       String fieldId = null;
       Iterator<String> keys = formularMsgMap.keySet().iterator();
       while (keys.hasNext()) {
         key = keys.next();
         fieldId = key.substring(0, key.lastIndexOf("_"));
         list = formular_fields_map.get(formularMsgMap.get(key));
         if (list == null) {
           list = new ArrayList<Field>();
         }
         boolean temp = true;
         if (ds.getField(fieldId).getSourceField()
             != null) { // 当前field包含sourcefield,list中移除sourcefield。
           for (Field f : list) {
             if (f.getId().equals(ds.getField(fieldId).getSourceField())) {
               list.remove(f);
               break;
             }
           }
         } else { // 当前field不包含sourcefield,判断当前field是否是list中某个field的sourcefield。
           for (Field f : list) {
             if (ds.getField(fieldId).getId().equals(f.getSourceField())) {
               temp = false;
               break;
             }
           }
         }
         if (temp) {
           list.add(ds.getField(fieldId));
           formular_fields_map.put(formularMsgMap.get(key), list);
         }
       }
       error_fields_map.putAll(formularMsgMap);
     }
     // 平台默认验证-错误信息分类
     validatorMap.put("type_fields_map", type_fields_map);
     // 自定义公式验证-错误信息分类
     validatorMap.put("formular_fields_map", formular_fields_map);
     // field错误信息集合
     validatorMap.put("error_fields_map", error_fields_map);
   }
   return validatorMap;
 }
Пример #3
0
 /**
  * 表格数据验证
  *
  * @param ds
  * @param gridcomp
  */
 public void validate(Dataset ds, GridComp gc) {
   if (gc != null) {
     // 隐藏整体错误提示框
     gc.hideErrorMsg();
     List<IGridColumn> columns = gc.getColumnList();
     if (columns != null && columns.size() > 0) {
       Field field = null;
       for (IGridColumn colum : columns) {
         if (colum instanceof GridColumn) {
           field = ds.getField(((GridColumn) colum).getField());
           if (field != null && field.isRequire()) { // field存在并且允许为空,则取gridColumn的非空校验规则.
             field.setRequire(((GridColumn) colum).isRequire());
           }
         }
       }
     }
   }
   Map<String, Object> validatorMap = validator(ds);
   if (validatorMap == null) {
     return;
   }
   validatorMap = dealValidator(validatorMap, ds);
   // 所有错误信息 key-fieldid value-errorMsg
   Map<String, String> error_fields_map =
       (Map<String, String>) validatorMap.get("error_fields_map");
   if (error_fields_map != null && !error_fields_map.isEmpty()) {
     UIPartMeta uimeta = AppSession.current().getViewContext().getUIMeta();
     ViewPartMeta widget = AppSession.current().getViewContext().getView();
     ViewPartComps vc = widget.getViewComponents();
     if (gc != null
         && uimeta.findChildById(gc.getId()) != null
         && ds.getId().equals((gc.getDataset()))) {
       // 错误标题序号
       int index = 1;
       StringBuffer allErrorMsg =
           new StringBuffer(Validator.getValidatorMsg(ValidatorType.saveFailure.ordinal()));
       // 平台默认验证-错误信息分类
       Map<Integer, List<Field>> type_fields_map =
           (Map<Integer, List<Field>>) validatorMap.get("type_fields_map");
       if (type_fields_map != null && !type_fields_map.isEmpty()) {
         List<Field> list = null;
         ValidatorType[] types = ValidatorType.values();
         for (ValidatorType type : types) {
           list = type_fields_map.get(type.ordinal());
           if (list != null && list.size() > 0) {
             index =
                 getFieldErrorMsgByErrorType(
                     allErrorMsg,
                     list,
                     gc,
                     index,
                     Validator.getValidatorMsg(ValidatorType.followingMsg.ordinal())
                         + Validator.getValidatorMsg(type.ordinal())
                         + ":");
           }
         }
       }
       // 自定义公式验证-错误信息分类
       Map<String, List<Field>> formular_fields_map =
           (Map<String, List<Field>>) validatorMap.get("formular_fields_map");
       if (formular_fields_map != null && !formular_fields_map.isEmpty()) {
         List<Field> list = null;
         String key = null;
         Iterator<String> keys = formular_fields_map.keySet().iterator();
         while (keys.hasNext()) {
           key = keys.next();
           list = formular_fields_map.get(key);
           if (list != null && list.size() > 0) {
             index = getFieldErrorMsgByErrorType(allErrorMsg, list, gc, index, key + ":");
           }
         }
       }
       if (index > 1) {
         LuiValidateException exception = new LuiValidateException(allErrorMsg.toString());
         exception.setViewId(widget.getId());
         exception.addComponentId(gc.getId());
         exception.setElementMap(error_fields_map);
         throw exception;
       }
     }
   }
 }