DefaultMapping mapping = new DefaultMapping(source, target); mapping.setRequired(binding.getRequired()); if (binding.getConverter() != null) { Assert.notNull(conversionService, "A ConversionService must be configured to use resolve custom converters to use during binding"); ConversionExecutor conversionExecutor = conversionService.getConversionExecutor(binding.getConverter(), String.class, target.getValueType(model)); mapping.setTypeConverter(conversionExecutor);
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; } }
private void addMapping(DefaultMapper mapper, Binding binding, Object model) { Expression source = new RequestParameterExpression(binding.getProperty()); ParserContext parserContext = new FluentParserContext().evaluate(model.getClass()); Expression target = expressionParser.parseExpression(binding.getProperty(), parserContext); DefaultMapping mapping = new DefaultMapping(source, target); mapping.setRequired(binding.getRequired()); if (binding.getConverter() != null) { ConversionExecutor conversionExecutor = conversionService.getConversionExecutor(binding.getConverter(), String.class, target.getValueType(model)); mapping.setTypeConverter(conversionExecutor); } if (logger.isDebugEnabled()) { logger.debug("Adding mapping for parameter '" + binding.getProperty() + "'"); } mapper.addMapping(mapping); }
DefaultMapping mapping = new DefaultMapping(source, target); mapping.setRequired(binding.getRequired()); if (binding.getConverter() != null) { Assert.notNull(conversionService, "A ConversionService must be configured to use resolve custom converters to use during binding"); ConversionExecutor conversionExecutor = conversionService.getConversionExecutor(binding.getConverter(), String.class, target.getValueType(model)); mapping.setTypeConverter(conversionExecutor);
/** * Gets the converterId for the binding with the specified name. Returns null if either a binding or a converterId * for the given name is not found. * * @param name the name of the binding. * @return the binding */ public String getConverterId(String name) { Binding binding = getBinding(name); if (binding != null) { return binding.getConverter(); } else { return null; } }
/** * Gets the converterId for the binding with the specified name. Returns null if either a binding or a converterId * for the given name is not found. * * @param name the name of the binding. * @return the binding */ public String getConverterId(String name) { Binding binding = getBinding(name); if (binding != null) { return binding.getConverter(); } else { return null; } }