File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Compile-time error for Struts 2 Custom Type Converter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Compile-time error for Struts 2 Custom Type Converter" Watch "Compile-time error for Struts 2 Custom Type Converter" New topic
Author

Compile-time error for Struts 2 Custom Type Converter

Johnnie Smith
Greenhorn

Joined: May 02, 2012
Posts: 22
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)
{
try
{
String s[]=(String[])value;
s[0]=s[0].replaceAll(",","");
return toType.cast(Double.parseDouble(s[0]));
}catch(NumberFormatException e)
{
System.out.println(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.


Versions
jdk: 1.6 Update 14
Tomcat: 6.0
Struts: 2.3.15.1

Thanks & Regards,
John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compile-time error for Struts 2 Custom Type Converter
 
Similar Threads
Simple J2SE 5.0 Tiger Notes
DefaultTypeConverter Problem
Overriding rule for generics
problems with custom converters and move from Struts 2.0.11 to 2.1.6
struts 2 converter on Set data type