/** * Dedicated method to support I10N and conversion errors * * @param key message which contains formatting string * @param expr that should be formatted * @return formatted expr with format specified by key */ public String getFormatted(String key, String expr) { Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors(); if (conversionErrors.containsKey(expr)) { String[] vals = (String[]) conversionErrors.get(expr); return vals[0]; } else { final ValueStack valueStack = ActionContext.getContext().getValueStack(); final Object val = valueStack.findValue(expr); return getText(key, Arrays.asList(val)); } }
/** * The validation implementation must guarantee that setValidatorContext will * be called with a non-null ValidatorContext before validate is called. * * @param object * @throws ValidationException */ @Override public void doValidate(Object object) throws ValidationException { String fieldName = getFieldName(); String fullFieldName = getValidatorContext().getFullFieldName(fieldName); ActionContext context = ActionContext.getContext(); Map<String, Object> conversionErrors = context.getConversionErrors(); if (conversionErrors.containsKey(fullFieldName)) { if ((defaultMessage == null) || ("".equals(defaultMessage.trim()))) { defaultMessage = XWorkConverter.getConversionErrorMessage(fullFieldName, context.getValueStack()); } addFieldError(fieldName, object); } }
Map<String, Object> conversionErrors = invocationContext.getConversionErrors(); ValueStack stack = invocationContext.getValueStack();
public void repopulateField(Object object) throws ValidationException { Map<String, Object> conversionErrors = ActionContext.getContext().getConversionErrors();