format bugs

persistence manager bugs
This commit is contained in:
Keith Donald
2008-03-27 10:41:51 +00:00
parent d75b3ca64c
commit 98045d99a6
4 changed files with 26 additions and 13 deletions

View File

@@ -23,6 +23,7 @@ import java.util.Locale;
import org.springframework.binding.format.Formatter;
import org.springframework.binding.format.InvalidFormatException;
import org.springframework.util.StringUtils;
public class DateFormatter implements Formatter {
@@ -47,10 +48,16 @@ public class DateFormatter implements Formatter {
}
public String format(Object date) {
if (date == null) {
return "";
}
return getDateFormat().format((Date) date);
}
public Object parse(String formattedString) throws InvalidFormatException {
if (!StringUtils.hasText(formattedString)) {
return null;
}
DateFormat dateFormat = getDateFormat();
try {
return dateFormat.parse(formattedString);

View File

@@ -22,6 +22,7 @@ import org.springframework.binding.format.Formatter;
import org.springframework.binding.format.InvalidFormatException;
import org.springframework.util.Assert;
import org.springframework.util.NumberUtils;
import org.springframework.util.StringUtils;
public class NumberFormatter implements Formatter {
@@ -39,6 +40,9 @@ public class NumberFormatter implements Formatter {
}
public String format(Object number) {
if (number == null) {
return "";
}
if (pattern != null) {
return getNumberFormat().format(number);
} else {
@@ -46,11 +50,14 @@ public class NumberFormatter implements Formatter {
}
}
public Object parse(String text) throws InvalidFormatException {
public Object parse(String formattedString) throws InvalidFormatException {
if (!StringUtils.hasText(formattedString)) {
return null;
}
if (pattern != null) {
return NumberUtils.parseNumber(text, numberClass, getNumberFormat());
return NumberUtils.parseNumber(formattedString, numberClass, getNumberFormat());
} else {
return NumberUtils.parseNumber(text, numberClass);
return NumberUtils.parseNumber(formattedString, numberClass);
}
}