Im che ha questo errore ogni volta che entro in una stringa vuota nella casella di testo e cercare di salvarlo Im che ha questo errore:riuscito a convertire il valore della proprietà di tipo java.lang.String al tipo richiesto doppia
Failed to convert property value of type java.lang.String to
required type double for property customerAcctSetting.maxAllowableAmount;
nested exception is java.lang.IllegalArgumentException: Cannot convert value of
type [java.lang.String] to required type [double] for
property maxAllowableAmount:
PropertyEditor [bp.ar.util.NumberFormatUtil$CustomerDoubleEditor] returned
inappropriate value
Ma quando entro in un formato numero non valido, ad esempio "ddd" ho questo errore:
Failed to convert property value of type java.lang.String to required
type double for property customerAcctSetting.maxAllowableAmount;
nested exception is java.lang.NumberFormatException: For input string: "ddd"
ho questo legante in mio controller:
@InitBinder
public void initBinder(WebDataBinder binder) {
NumberFormatUtil.registerDoubleFormat(binder);
}
E ho una classe NumberFormatUtil.java
che implementa la funzione statica registerDoubleFormat(binder)
:
NumberFormatUtil.java
public static void registerDoubleFormat (WebDataBinder binder) {
binder.registerCustomEditor(Double.TYPE, new CustomerDoubleEditor());
}
private static class CustomerDoubleEditor extends PropertyEditorSupport{
public String getAsText() {
Double d = (Double) getValue();
return d.toString();
}
public void setAsText(String str) {
if(str == "" || str == null)
setValue(0);
else
setValue(Double.parseDouble(str));
}
}
Im usando Primavera 3.0.1. Im molto nuovo a Java e altre tecnologie correlate come la primavera. Per favore aiuto. Grazie in anticipo.
Quindi qual è la risposta? Leggendo i forum di Spring sembra che questo dovrebbe funzionare. Viene visualizzato il messaggio "Impossibile convertire il valore della proprietà di tipo [java.lang.Double] nel tipo richiesto [java.lang.Double] per la proprietà ..." che mi stordisce. –