本文整理匯總了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()));
}
}
示例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()]);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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());
}
}
示例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();
}
}
示例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();
}
示例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;
}
示例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;
}
示例11: apply
import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
@Override
public String apply(@Nonnull ObjectError error) {
return TAB + error.getDefaultMessage();
}
示例12: createError
import org.springframework.validation.ObjectError; //導入方法依賴的package包/類
protected Error createError(ObjectError error) {
return new Error(error.getDefaultMessage(), "Invalid '" + getField(error) + "' value: " + getRejectedValue(error));
}
示例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();
}
示例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();
}
示例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());
}