IN PROGRESS - issue SWF-720: Multiple checkboxes to Collection mapping

http://jira.springframework.org/browse/SWF-720
This commit is contained in:
Keith Donald
2008-06-23 14:19:54 +00:00
parent f7d0ec1008
commit 301931e617
6 changed files with 18 additions and 11 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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");
}

View File

@@ -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 {

View File

@@ -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");
}