i have a java web application using struts2 (vers: 2.3.15) and I need to apply type convertion to a int
I wrote the following code:
package sistema.conversores;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Map;
import org.apache.struts2.util.StrutsTypeConverter;
/**
*
* @author Administrador
*/
public class IntegerConverter extends StrutsTypeConverter {
public Object convertFromString(Map context, String[] values, Class toClass) {
System.out.println("load");
if (values.length != 1) {
super.performFallbackConversion(context, values, toClass);
}
System.out.println("conversion");
final String numero = values[0];
try {
return Integer.parseInt(numero);
} catch (Exception e) {
return 0;
}
}
public String convertToString(Map context, Object o) {
final NumberFormat formatter = new DecimalFormat("#0");
System.out.println("lectura");
if (o instanceof Integer) {
return formatter.format(o);
} else {
return String.valueOf(o);
}
}
}
And append it to xwork-conversion.properties
# syntax: <type> = <converterClassName>
int = sistema.conversores.IntegerConverter
java.util.Date = sistema.conversores.DateConverter
But the int type conversion dont run, any other conversion run fine, Also the int type conversion work fine in struts2 vers 2.1.6
How can I fix this?