private int getFieldErrorMsgByErrorType( StringBuffer allErrorMsg, List<Field> list, GridComp gc, int index, String titleError) { List<IGridColumn> fes = gc.getAllColumnList(); if (fes != null && fes.size() > 0) { boolean isNeedToShowError = false; IGridColumn[] gridColumns = new IGridColumn[fes.size()]; int size = list.size(); for (int i = 0; i < size; i++) { Field f = list.get(i); IGridColumn col = gc.getColumnByField(f.getField()); if (col != null && col.isVisible()) { for (int k = 0; k < fes.size(); k++) { if (col.getId().equals(fes.get(k).getId())) { gridColumns[k] = col; break; } } isNeedToShowError = true; } } if (isNeedToShowError) { allErrorMsg.append(((index > 1) ? " " : "") + index + ")"); index++; allErrorMsg.append(titleError); boolean temp = false; for (int i = 0; i < gridColumns.length; i++) { if (gridColumns[i] != null) { String text = null; if (gridColumns[i] instanceof GridColumn) { text = ((GridColumn) gridColumns[i]).getText(); } else if (gridColumns[i] instanceof GridColumnGroup) { text = ((GridColumnGroup) gridColumns[i]).getText(); } allErrorMsg.append(((temp) ? "," : "") + "“" + text + "”"); temp = true; } } } } return index; }
/** * 表格数据验证 * * @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; } } } }