Skip to content

Commit

Permalink
DecimalTextField compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Jan 18, 2016
1 parent 1a07137 commit 055850c
Showing 1 changed file with 7 additions and 6 deletions.
Expand Up @@ -26,23 +26,23 @@ public class DecimalTextField extends TextField<Double> {

private NumberFormat format;

private IConverter decimalConverter;
private IConverter<Double> decimalConverter;

public DecimalTextField(String id, IModel<Double> model) {
super(id, model, Double.class);
format = DecimalFormat.getInstance();
format.setMaximumFractionDigits(16);

decimalConverter = new IConverter() {
decimalConverter = new IConverter<Double>() {
private static final long serialVersionUID = 1L;

@Override
public String convertToString(Object value, Locale locale) {
public String convertToString(Double value, Locale locale) {
return value == null? null : format.format(value);
}

@Override
public Object convertToObject(String value, Locale locale) {
public Double convertToObject(String value, Locale locale) {
if (value == null || value.trim().length() == 0) {
return null;
}
Expand All @@ -62,8 +62,9 @@ public void setMaximumFractionDigits(int maximumFractionDigits) {
format.setMaximumFractionDigits(maximumFractionDigits);
}


@Override
public IConverter getConverter(Class<?> type) {
return decimalConverter;
public <C> IConverter<C> getConverter(Class<C> type) {
return (IConverter<C>) decimalConverter;
}
}

0 comments on commit 055850c

Please sign in to comment.