IN PROGRESS - issue SWF-720: Multiple checkboxes to Collection mapping
http://jira.springframework.org/browse/SWF-720
This commit is contained in:
@@ -32,9 +32,10 @@ public interface FormatterRegistry {
|
||||
/**
|
||||
* Returns the formatter for the given class of object with the given id. Use this method to query a custom
|
||||
* formatter instance for a given class of object.
|
||||
* @param clazz the type of object that will be formatted
|
||||
* @param id the id of the custom formatter instance; typically descriptive like "localDate"
|
||||
* @return the formatter
|
||||
*/
|
||||
public Formatter getFormatter(String id);
|
||||
public Formatter getFormatter(Class clazz, String id);
|
||||
|
||||
}
|
||||
@@ -42,9 +42,13 @@ public class GenericFormatterRegistry implements FormatterRegistry {
|
||||
return (Formatter) formattersByClass.get(clazz);
|
||||
}
|
||||
|
||||
public Formatter getFormatter(String id) {
|
||||
public Formatter getFormatter(Class clazz, String id) {
|
||||
Assert.notNull(clazz, "The formatted class argument is required");
|
||||
Assert.hasText(id, "The id of the custom formatter is required");
|
||||
return (Formatter) formattersById.get(id);
|
||||
Formatter formatter = (Formatter) formattersById.get(id);
|
||||
if (formatter != null && formatter.getObjectType().equals(clazz)) {
|
||||
}
|
||||
return formatter;
|
||||
}
|
||||
|
||||
// impl
|
||||
|
||||
@@ -45,7 +45,7 @@ public class GenericFormatterRegistryTests extends TestCase {
|
||||
NumberFormatter percentFormatter = new NumberFormatter(BigDecimal.class);
|
||||
percentFormatter.setPattern("00%");
|
||||
registry.registerFormatter("percent", percentFormatter);
|
||||
Formatter formatter = registry.getFormatter("percent");
|
||||
Formatter formatter = registry.getFormatter(Integer.class, "percent");
|
||||
assertEquals("35%", formatter.format(new BigDecimal(".35")));
|
||||
BigDecimal value = (BigDecimal) formatter.parse("35%");
|
||||
assertEquals(new BigDecimal(".35"), value);
|
||||
@@ -54,9 +54,9 @@ public class GenericFormatterRegistryTests extends TestCase {
|
||||
public void testRegisterCustomFormatterBogusLookupId() {
|
||||
registry.registerFormatter(new NumberFormatter(Integer.class));
|
||||
registry.registerFormatter("double", new NumberFormatter(Double.class));
|
||||
Formatter formatter = registry.getFormatter("bogusFormat");
|
||||
Formatter formatter = registry.getFormatter(Integer.class, "bogusFormat");
|
||||
assertNull(formatter);
|
||||
formatter = registry.getFormatter("double");
|
||||
formatter = registry.getFormatter(Double.class, "double");
|
||||
assertNotNull(formatter);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,8 @@ public class FacesFlowBuilderServicesBeanDefinitionParserTests extends TestCase
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) throws ConversionExecutionException {
|
||||
public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass)
|
||||
throws ConversionExecutionException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ public class FacesFlowBuilderServicesBeanDefinitionParserTests extends TestCase
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public Formatter getFormatter(String id) {
|
||||
public Formatter getFormatter(Class clazz, String id) {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
|
||||
@@ -513,7 +513,7 @@ public abstract class AbstractMvcView implements View {
|
||||
|
||||
private Formatter getFormatter(Expression target, Class targetClass) {
|
||||
if (formatterRegistry != null) {
|
||||
Formatter formatter = formatterRegistry.getFormatter(target.getExpressionString());
|
||||
Formatter formatter = formatterRegistry.getFormatter(targetClass, target.getExpressionString());
|
||||
if (formatter != null) {
|
||||
return formatter;
|
||||
} else {
|
||||
|
||||
@@ -71,7 +71,8 @@ public class FlowBuilderServicesBeanDefinitionParserTests extends TestCase {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass) throws ConversionExecutionException {
|
||||
public ConversionExecutor[] getConversionExecutorsForSource(Class sourceClass)
|
||||
throws ConversionExecutionException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ public class FlowBuilderServicesBeanDefinitionParserTests extends TestCase {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
public Formatter getFormatter(String id) {
|
||||
public Formatter getFormatter(Class clazz, String id) {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user