• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compile-time error for Struts 2 Custom Type Converter

Johnnie Smith
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a HTML form in a Struts application that accepts data pertaining to a billing process. On this form there is a field called amount.

I want to accept a double value for this field and assign it to a bean property named amount of type double.

I am attempting to write my own custom type converter that will accept a double value with a comma present in it like 8,567.00.

I am extending DefaultTypeConverter and overriding its convertValue() method.

As per document at the following location "http://commons.apache.org/proper/commons-ognl/apidocs/org/apache/commons/ognl/DefaultTypeConverter.html", this method has the following signature:

public <T> T convertValue(Map<String,Object> context,Object value,Class<T> toType)

So I wrote the following code:

package mypack;

import java.text.*;
import java.util.*;
import ognl.DefaultTypeConverter;

public class DoubleConverter extends DefaultTypeConverter {

public <T> T convertValue(Map<String,Object> context,Object value,Class<T> toType)

if (toType == String.class)
NumberFormat formatter = new DecimalFormat("#,##0.00");
return toType.cast(formatter.format((Double)value));
else if (toType == Double.class || toType == Double.TYPE)
String s[]=(String[])value;
return toType.cast(Double.parseDouble(s[0]));
}catch(NumberFormatException e)
return null;

I am getting the following compile-time error.

Name clash: The method convertValue(Map<String,Object>, Object, Class<T>) of type DoubleConverter has the same erasure as convertValue(Map, Object, Class) of type DefaultTypeConverter but does not override it

I have taken the signature of convertValue() that is specified in the above-mentioned document.

So I am not able to understand why I am getting this error and why the message says that "but does not override it" when I am clearly overriding the superclass' convertValue() method.

As far as I know, this error should arise only in case there are 2 overloaded methods that are supposedly distinct have the same erasure. Here I am not writing any other method.

Please shed some light on this problem.

jdk: 1.6 Update 14
Tomcat: 6.0

Thanks & Regards,
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!