public boolean test(MappingResult result) { if (property.equals(result.getMapping().getTargetExpression().getExpressionString())) { return true; } else { return false; } } }
private Object getFormattedValue(String field) { Expression fieldExpression = parseFieldExpression(field, true); Class<?> valueType = fieldExpression.getValueType(boundObject); if (isCustomConverterConfigured(field) || avoidConversion(valueType)) { fieldExpression = parseFieldExpression(fieldExpression.getExpressionString(), false); } Object value = fieldExpression.getValue(boundObject); if ((value instanceof String) == false) { if (avoidConversion(valueType) == false) { PropertyEditor editor = findSpringConvertingPropertyEditor(field, valueType); if (editor != null) { editor.setValue(value); value = editor.getAsText(); } } } return value; }
protected MessageResolver createMessageResolver(MappingResult error) { String model = getModelExpression().getExpressionString(); String field = error.getMapping().getTargetExpression().getExpressionString(); Class<?> fieldType = error.getMapping().getTargetExpression().getValueType(getModelObject()); String[] messageCodes = messageCodesResolver.resolveMessageCodes(error.getCode(), model, field, fieldType); return new MessageBuilder().error().source(field).codes(messageCodes).resolvableArg(field) .defaultText(error.getCode() + " on " + field).build(); }
public View getView(RequestContext context) { String viewId = (String) this.viewId.getValue(context); return new MockView(viewId, context); } }
public Class<?> getFieldType(String field) { return parseFieldExpression(fixedField(field), false).getValueType(boundObject); }
/** * Expose given bean method return value in given flow execution request context. * @param result the return value * @param context the request context */ public void exposeResult(Object result, RequestContext context) { resultExpression.setValue(context, applyTypeConversionIfNecessary(result)); }
/** * Evaluate this method parameter against the provided argument source, returning a single method argument value. * @param argumentSource the meyhod argument source * @param context the evaluation context * @return the method argument value */ public Object evaluateArgument(Object argumentSource, EvaluationContext context) { return name.evaluate(argumentSource, context); }
private Object getModelObject() { Expression model = getModelExpression(); if (model != null) { try { return model.getValue(requestContext); } catch (EvaluationException e) { return null; } } else { return null; } }
private ConversionExecutor getConverter(Expression fieldExpression) { if (conversionService != null) { Class valueType = fieldExpression.getValueType(boundObject); // special handling for array, collection, map types // necessary as getFieldValue is called by form tags for non-formattable properties, too // TODO - investigate how to improve this in Spring MVC if (valueType == null || valueType.isArray() || Collection.class.isAssignableFrom(valueType) || Map.class.isAssignableFrom(valueType)) { return null; } if (binderConfiguration != null) { Binding binding = binderConfiguration.getBinding(fieldExpression.getExpressionString()); if (binding != null) { String converterId = binding.getConverter(); if (converterId != null) { return conversionService.getConversionExecutor(converterId, valueType, String.class); } } } return conversionService.getConversionExecutor(valueType, String.class); } else { return null; } }
/** * Adds a special {@link DefaultMapping} that results in setting the target field on the model to an empty value * (typically null). * * @param mapper the mapper to add the mapping to * @param field the field for which a mapping is to be added * @param model the model */ protected void addEmptyValueMapping(DefaultMapper mapper, String field, Object model) { ParserContext parserContext = new SimpleParserContext(model.getClass()); Expression target = emptyValueExpressionParser.parseExpression(field, parserContext); try { Class<?> propertyType = target.getValueType(model); Expression source = new StaticExpression(getEmptyValue(propertyType)); DefaultMapping mapping = new DefaultMapping(source, target); if (logger.isDebugEnabled()) { logger.debug("Adding empty value mapping for parameter '" + field + "'"); } mapper.addMapping(mapping); } catch (EvaluationException e) { } }
public void testSetValueCoersionError() { String expressionString = "maximum"; Expression exp = parser.parseExpression(expressionString, null); TestBean context = new TestBean(); try { exp.setValue(context, "bogus"); fail("Should have failed with coersion"); } catch (ValueCoercionException e) { } }
public Object evaluate(Object target, EvaluationContext context) throws EvaluationException { return collectionExpression.evaluate(target, context); }
protected Event doExecute(RequestContext context) throws Exception { Object result = expression.getValue(context); if (result instanceof Action) { return ActionExecutor.execute((Action) result, context); } else { if (resultExpression != null) { resultExpression.setValue(context, result); } return resultEventFactory.createResultEvent(this, result, context); } }
public boolean test(MappingResult result) { if (result.isError() && field.equals(result.getMapping().getTargetExpression().getExpressionString())) { return true; } else { return false; } } }
public Object getValue(Object context) throws EvaluationException { String subflowId = (String) this.subflowId.getValue(context); return flowDefinitionLocator.getFlowDefinition(subflowId); }
private Object getFormattedValue(String field) { Expression fieldExpression = parseFieldExpression(field, true); Class<?> valueType = fieldExpression.getValueType(boundObject); if (isCustomConverterConfigured(field) || avoidConversion(valueType)) { fieldExpression = parseFieldExpression(fieldExpression.getExpressionString(), false); } Object value = fieldExpression.getValue(boundObject); if ((value instanceof String) == false) { if (avoidConversion(valueType) == false) { PropertyEditor editor = findSpringConvertingPropertyEditor(field, valueType); if (editor != null) { editor.setValue(value); value = editor.getAsText(); } } } return value; }
protected MessageResolver createMessageResolver(MappingResult error) { String model = getModelExpression().getExpressionString(); String field = error.getMapping().getTargetExpression().getExpressionString(); Class<?> fieldType = error.getMapping().getTargetExpression().getValueType(getModelObject()); String[] messageCodes = messageCodesResolver.resolveMessageCodes(error.getCode(), model, field, fieldType); return new MessageBuilder().error().source(field).codes(messageCodes).resolvableArg(field) .defaultText(error.getCode() + " on " + field).build(); }
private PropertyEditor findSpringConvertingPropertyEditor(String field, Class<?> valueType) { if (conversionService != null) { String converterId = null; if (field != null) { if (binderConfiguration != null) { converterId = binderConfiguration.getConverterId(field); } if (valueType == null) { valueType = parseFieldExpression(field, false).getValueType(boundObject); } } if (valueType != null) { BeanWrapper accessor = PropertyAccessorFactory.forBeanPropertyAccess(boundObject); TypeDescriptor typeDescriptor = accessor.getPropertyTypeDescriptor(field); return new ConvertingPropertyEditorAdapter(conversionService, converterId, typeDescriptor); } else { return null; } } else { return null; } }
public void testSetValueCoersionError() { String expressionString = "maximum"; Expression exp = parser.parseExpression(expressionString, null); TestBean context = new TestBean(); try { exp.setValue(context, "bogus"); fail("Should have failed with coersion"); } catch (ValueCoercionException e) { } }