struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <ahardy.str...@cyberspaceroad.com>
Subject Re: Enum, TypeConversion and error handling
Date Fri, 04 Jan 2008 10:46:46 GMT
Dave Newton on 04/01/08 00:09, wrote:
> --- Adam Hardy <ahardy.struts@cyberspaceroad.com> wrote:
>> Fresh from plugging in my first TypeConverter, I find that on the whole the
>> TypeConversion mechanism in S2 is very good. After setting up a custom type
>> converter, I thought I could chip in with a couple of comments:
>>
>> (1) where to register type converter
> 
> Which part was confusing? It says to put it in
> ClassName-conversion.properties or the XWork conversion file.

Obviously I did manage to work it out, but when I started, I thought:

- which ClassName? (the Action, or the class to be converted, or the javabean 
parent it was nested in, etc - when you don't know, the variety is infinite!)
- which package does it go in?
- when you don't fully qualify the class, (e.g. 'point'), what does the name 
refer to? Is it the property on the action?

>> (2) S2 swallows exceptions in XworkConverter.  I couldn't figure out
>> whether the type converter registration had even worked.
> 
> Well, putting logging in your convertor should have at least shown if your
> conversion methods were being called, no?

Sure, but I was trying to follow the docs by throwing TypeConversionExceptions, 
so it seemed that I'd messed it up somehow because I never saw any. Then I 
realised they would never have seen the light of day anyway, so it was at least 
misleading to suggest throwing them.

> When I was dinking around w/ convertors I occasionally would wrap my code
> with Exception catches, but I agree that there are exceptions that are
> difficult to get at under normal circumstances. This is on my list, but I'm
> completely swamped right now.

I can appreciate that! Anyone who finds any time for open source in a commercial 
environment has my admiration - long may it last.

Ideally those catch blocks in XWorkConverter should be catching only 
TypeConversionExceptions, and any other exception type should be uncaught, 
breaking the process.


>> (2b) it was difficult to tell exactly what I should do in my TypeConverter
>> to show the message that I really wanted when conversion failed.
> 
> I'm not sure what you mean by that.

I haven't quite figured out the way that conversion error messages are chosen, 
but it would be cool to tie them in with the exception, for instance:

throw new TypeConversionException("someaction.thistype.nonNumeric");

or

throw new TypeConversionException("someaction.thistype.nullNotAllowed");

As I say though I haven't got so far as to find out how flexible the XWork 
converter is.

Regards
Adam

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message