Title: Message
Does the class you're using have a get method for the same property name as a String? I'm just wondering if it's getting confused...
-----Original Message-----
From: Cameron Braid [mailto:[EMAIL PROTECTED]
Sent: Monday, October 06, 2003 4:01 AM
To: [EMAIL PROTECTED]
Subject: RE: [OS-webwork] TypeConverter - exception for Long values when given empty string

nope.. the code that is there works fine, because the convertValue(...) is re-entrant for the case where the value is an array.
 
so result does get set to OK_NULL_RESULT, and then returned as null.
 
What I think is happening internally with ognl is that since the value is being returned as null, the original value's class is used when invoking the set method (ie String[]).  When you return a non null value, I presume that ognl use that value's class instead of the input value's class.
 
i.e
for a convertion to a value from String[] {""} -> Long(1) ognl will detect that the new type is Long.class and look for a setId(Long)
 
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Fred Lamuette
Sent: Monday, 6 October 2003 5:45 PM
To: [EMAIL PROTECTED]
Subject: RE: [OS-webwork] TypeConverter - exception for Long values when given empty string

Obviously, it doesnt work, and the error comes from a bad test in the convertValue(...) method.
 
The code :
if( "".equald(value)) {
    result = (String.class.equals(toType)) ? "" : OK_NULL_RESULT;
    return result;
}
 
has to be changed for :
 
if( value instanceof String[] ) && ( ((String[]) value)[0].trim().length()==0 ) ) {
    result = (String.class.equals(toType)) ? "" : OK_NULL_RESULT;
    return result;
}
 
Cheers.

Richard HALLIER
Chef de projet
[EMAIL PROTECTED]
01.40.12.41.52
www.uniclick.org
UNICLICK
 

-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]De la part de Cameron Braid
Envoyé : lundi 6 octobre 2003 05:30
À : [EMAIL PROTECTED]
Objet : RE: [OS-webwork] TypeConverter - exception for Long values when given empty string

Sorry to say, it doesn't work.
 
It does use your new code but, even though it returns a NULL value for the converted result, I am still getting an exception :
 
/-- Encapsulated exception ------------\
java.lang.NoSuchMethodException: setId([Ljava.lang.String;)
 at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:613)
 at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:761)
 at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:76)
 at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:132)
I presue this is because it still thinks the type of the property (even after the conversion) is still String[]
 
therefore it wants to setId((String[])null) which it can't find as a valid method.
 
I dunno the soloution here... Maybe someone with ognl experience can help ?
 
Cameron
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jason Carreira
Sent: Sunday, 5 October 2003 11:41 PM
To: [EMAIL PROTECTED]
Subject: RE: [OS-webwork] TypeConverter - exception for Long values when given empty string

I've fixed this in CVS... I chose C :-)
-----Original Message-----
From: Cameron Braid [mailto:[EMAIL PROTECTED]
Sent: Friday, October 03, 2003 3:02 AM
To: [EMAIL PROTECTED]
Subject: [OS-webwork] TypeConverter - exception for Long values when given empty string

I am getting an exception from the params interceptor.
 
I have an action with a setId(Long), and a hidden form field called id that initially has an empty string value.
 
This used to work, until the exception handeling was improved with the type converters.  Now, I get this error :
 
 id - [Invalid field value for field "id".]
 
which is because of  java.lang.NumberFormatException: For input string: ""
in XWorkBasicConverter.super.convertValue(context, value, toType); at line 85.
 
I can see a couple of soloutions
 
a) in my forms, don't render the hidden input if there is no value for id (fair bit of work)
b) create a custom type converter for Long (and other numeric types) that convert empty string to null (fairly easy)
c) modify the XWorkBasicConverter to support the empty string to null conversion for Number types.  (every one can use this)
 
What are your thoughts ?
 
Cameron

Reply via email to