當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjectError.getDefaultMessage方法代碼示例

本文整理匯總了Java中org.springframework.validation.ObjectError.getDefaultMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java ObjectError.getDefaultMessage方法的具體用法?Java ObjectError.getDefaultMessage怎麽用?Java ObjectError.getDefaultMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.validation.ObjectError的用法示例。


在下文中一共展示了ObjectError.getDefaultMessage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolveError

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
private void resolveError(BasicResponse response, ObjectError error) {
    Locale currentLocale = LocaleContextHolder.getLocale();

    String defaultMessage = error.getDefaultMessage();
    if (StringUtils.isNotBlank(defaultMessage) && defaultMessage.startsWith("{DEMO-")) {
        String errorCode = defaultMessage.substring(1, defaultMessage.length() - 1);
        response.setErrorCode(errorCode);
        response.setErrorMessage(getLocalizedErrorMessage(errorCode, error.getArguments()));
    } else {
        String[] errorCodes = error.getCodes();
        for (String code : errorCodes) {
            String message = getLocalizedErrorMessage(currentLocale, code, error.getArguments());
            if (!code.equals(message)) {
                response.setErrorCode(code);
                response.setErrorMessage(message);
                return;
            }
        }

        response.setErrorCode(error.getCode());
        response.setErrorMessage(getLocalizedErrorMessage(error.getCode(), error.getArguments()));
    }
}
 
開發者ID:barrykalok,項目名稱:spring-boot-drools-example,代碼行數:24,代碼來源:ApiControllerAdvice.java

示例2: getI18nErrors

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
/**
 * JAVADOC Method Level Comments
 *
 * @param locale JAVADOC.
 * @param messageSource JAVADOC.
 * @param bindingResult JAVADOC.
 *
 * @return JAVADOC.
 */
protected String[] getI18nErrors(final BindingResult bindingResult) {
    List<String> errors = new ArrayList<String>();

    if ((bindingResult != null) && bindingResult.hasGlobalErrors()) {
        for (ObjectError objectError : bindingResult.getGlobalErrors()) {
            String message = objectError.getDefaultMessage();

            if (messageSource != null) {
                Locale loc = Locale.getDefault();

                try {
                    message = messageSource.getMessage(objectError.getCode(),
                            objectError.getArguments(), loc);
                } catch (Throwable t) {
                    //do nothing (just stick with the default message)
                }
            }

            errors.add(message);
        }
    }

    return errors.toArray(new String[errors.size()]);
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:34,代碼來源:LoaderExceptionFactory.java

示例3: asStringList

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
public static List<String> asStringList(BindingResult br, boolean appendFieldname){
	if(br==null || !br.hasErrors())
		return Collections.emptyList();
	List<String> msglist = new ArrayList<String>();
	String msg = null;
	for(ObjectError error : br.getAllErrors()){
		msg = "";
		if(appendFieldname && FieldError.class.isInstance(error)){
			FieldError fe = (FieldError) error;
			FieldName info = findValidationInfo(br.getTarget().getClass(), fe.getField());
			msg = info==null?fe.getField():info.value();
		}
		msg += error.getDefaultMessage();
		msglist.add(msg);
	}
	return msglist;
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:18,代碼來源:ValidatorUtils.java

示例4: handleMethodArgumentNotValid

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
    logger.debug("### RestResponseEntityExceptionHandler - handleMethodArgumentNotValid: reached.");

    List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
    List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors();
    List<String> errors = new ArrayList<String>(fieldErrors.size() + globalErrors.size());
    String error;
    for (FieldError fieldError : fieldErrors) {
        error = fieldError.getField() + ", " + fieldError.getDefaultMessage();
        errors.add(error);
    }
    for (ObjectError objectError : globalErrors) {
        error = objectError.getObjectName() + ", " + objectError.getDefaultMessage();
        errors.add(error);
    }
    ExceptionResponse exceptionResponse = new ExceptionResponse(ExceptionResponse.EXCEPTION_CODE_METHOD_ARGUMENT_NOT_VALID, "MethodArgumentNotValidException", ex.getMessage(), errors);
    return new ResponseEntity<Object>(exceptionResponse, HttpStatus.BAD_REQUEST);
}
 
開發者ID:bernfried,項目名稱:SimplePRP,代碼行數:20,代碼來源:RestControllerExceptionHandler.java

示例5: errorGlobal

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
public static void errorGlobal(
		HttpServletRequest request,
		BindingResult result,
		String textValidacio) {
	for (ObjectError error: result.getGlobalErrors()) {
		String errorText = (error.getDefaultMessage() == null || error.getDefaultMessage().isEmpty()) ? textValidacio : error.getDefaultMessage();
		error(request, errorText);
	}
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:10,代碼來源:MissatgesHelper.java

示例6: hasErrors

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
public static void hasErrors(BindingResult bindingResult, HttpServletRequest request) throws McBasicRestException{
    if (bindingResult.hasErrors()) {
        String combinedErrMsg = "";
        for (ObjectError err : bindingResult.getAllErrors()) {
            if (combinedErrMsg.length() != 0) {
                combinedErrMsg += ", ";
            }
            combinedErrMsg += err.getDefaultMessage();
        }
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, combinedErrMsg, request.getServletPath());
    }
}
 
開發者ID:MaritimeConnectivityPlatform,項目名稱:IdentityRegistry,代碼行數:13,代碼來源:ValidateUtil.java

示例7: getDefaultMessage

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
private String getDefaultMessage(MethodArgumentNotValidException ex) {
    FieldError error = ex.getBindingResult().getFieldError();
    ObjectError globalError = ex.getBindingResult().getGlobalError();
    if (error == null) {
        return globalError.getDefaultMessage();
    } else {
        return error.getDefaultMessage();
    }
}
 
開發者ID:g00glen00b,項目名稱:commutify,代碼行數:10,代碼來源:ControllerExceptionHandler.java

示例8: JsonWrapper

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
/**
 * 構造 {result: 'true', parm: {'p1': 'p1', 'p2': 'p2', ...} }
 * 
 * @param result 狀態值,true or false
 * @param eList 封裝ObjectError的List對象
 */	
public JsonWrapper(boolean result, List<ObjectError> eList) {
	// 構造內部JSON對象
	JsonObjectBuilder innerBuilder = Json.createObjectBuilder();
	int ix = 0;
	String key = null;
	String value = null;
	// 遍曆Error對象
	for (ObjectError err : eList) {
		if (err instanceof FieldError) {
			FieldError fErr = (FieldError)err;
			key = fErr.getField();
			value = fErr.getDefaultMessage();
		} else {
			key = Integer.toString(ix);
			value = err.getDefaultMessage();
		}
		
		// 把錯誤信息添加到JSON中
		innerBuilder.add(key, value);
		
		++ix;
	}
	
	// 構造外部JSON
	JsonObject json = Json.createObjectBuilder()
			.add("result", result)
			.add("parm", innerBuilder)
			.build();
	
	this.ajaxMessage = json.toString();
}
 
開發者ID:wswenyue,項目名稱:taolijie,代碼行數:38,代碼來源:JsonWrapper.java

示例9: getErrorMessage

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
public String getErrorMessage(ObjectError fe, ReturnableClosure<ObjectError, String> block){
	String fmsg = "";
	if(block!=null){
		fmsg = block.execute(fe);
	}else{
		if(fe!=null)
			fmsg = fe.getDefaultMessage();
	}
	return fmsg;
}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:11,代碼來源:ValidationBindingResult.java

示例10: getActionMessages

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
/**
 * Return an ActionMessages representation of this SpringBindingActionForm,
 * exposing all errors contained in the underlying Spring Errors object.
 * @see org.springframework.validation.Errors#getAllErrors()
 */
private ActionMessages getActionMessages() {
	ActionMessages actionMessages = new ActionMessages();
	Iterator it = this.errors.getAllErrors().iterator();
	while (it.hasNext()) {
		ObjectError objectError = (ObjectError) it.next();
		String effectiveMessageKey = findEffectiveMessageKey(objectError);
		if (effectiveMessageKey == null && !defaultActionMessageAvailable) {
			// Need to specify default code despite it not being resolvable:
			// Struts 1.1 ActionMessage doesn't support default messages.
			effectiveMessageKey = objectError.getCode();
		}
		ActionMessage message = (effectiveMessageKey != null) ?
				new ActionMessage(effectiveMessageKey, resolveArguments(objectError.getArguments())) :
				new ActionMessage(objectError.getDefaultMessage(), false);
		if (objectError instanceof FieldError) {
			FieldError fieldError = (FieldError) objectError;
			actionMessages.add(fieldError.getField(), message);
		}
		else {
			actionMessages.add(ActionMessages.GLOBAL_MESSAGE, message);
		}
	}
	if (logger.isDebugEnabled()) {
		logger.debug("Final ActionMessages used for binding: " + actionMessages);
	}
	return actionMessages;
}
 
開發者ID:Gert-Jan1966,項目名稱:spring-struts-forwardport,代碼行數:33,代碼來源:SpringBindingActionForm.java

示例11: apply

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
@Override
public String apply(@Nonnull ObjectError error) {
  return TAB + error.getDefaultMessage();
}
 
開發者ID:HotelsDotCom,項目名稱:circus-train,代碼行數:5,代碼來源:VacuumToolHelp.java

示例12: createError

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
protected Error createError(ObjectError error) {
    return new Error(error.getDefaultMessage(), "Invalid '" + getField(error) + "' value: " + getRejectedValue(error));
}
 
開發者ID:mkopylec,項目名稱:errorest-spring-boot-starter,代碼行數:4,代碼來源:BeanValidationErrorDataProvider.java

示例13: UIErrorDetail

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
UIErrorDetail(ObjectError error) {
    rejectedValue = null;
    path = error.getObjectName();
    message = "Invalid value for object '" + error.getObjectName() + "': " + error.getDefaultMessage();
}
 
開發者ID:luxons,項目名稱:seven-wonders,代碼行數:6,代碼來源:UIErrorDetail.java

示例14: AjaxResponse

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
public AjaxResponse(BindingResult result) {
    this.returnState = ReturnState.ERROR;
    this.returnMsg = "";
    for (ObjectError objectError : result.getAllErrors())
        this.returnMsg += objectError.getDefaultMessage();
}
 
開發者ID:Hope6537,項目名稱:hope-tactical-equipment,代碼行數:7,代碼來源:AjaxResponse.java

示例15: createViolation

import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
default Violation createViolation(final ObjectError error) {
    final String fieldName = formatFieldName(error.getObjectName());
    return new Violation(fieldName, error.getDefaultMessage());
}
 
開發者ID:zalando,項目名稱:problem-spring-web,代碼行數:5,代碼來源:BaseBindingResultAdviceTrait.java


注:本文中的org.springframework.validation.ObjectError.getDefaultMessage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。