You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2008/01/04 00:58:35 UTC

Enum, TypeConversion and error handling

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 - took a while to discover whether I was 
registering it as intended. The author of the documentation made several 
assumptions about the reader's knowledge of the mechanism that cause a bit of a 
hindrance to understanding what was meant. Unfortunately even though I have edit 
rights to the wiki, I can't change it because it's mostly extracted direct from 
the source code javadocs.

(1b) is it true that the type converter registration process doesn't check 
superclasses - java.lang.Enum for example? I wrote a generic enum converter but 
must register it against each individual enum class. I can see that I would like 
to register most enums with DefaultEnumTypeConverter (converts the text name of 
the enum element) but then I'd register some enums individually with an 
EnumOrdinalTypeConverter (converts an int into the ordinal).

(2) S2 swallows exceptions in XworkConverter. This caused a lot of wasted time. 
I couldn't figure out whether the type converter registration had even worked. I 
needed to step through code to find problem. The original exception admittedly 
was due to bad coding in my TypeConverter subclass, but the resulting exception 
was caught and discarded.

(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.

(3) I could certainly tweak the documentation but it's difficult with big quotes 
from javadoc - see my previous email to the dev list on this:

http://www.nabble.com/cwiki-to14472863.html





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


Re: Enum, TypeConversion and error handling

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Dave Newton on 04/01/08 00:09, wrote:
> --- Adam Hardy <ah...@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


Re: Enum, TypeConversion and error handling

Posted by Dave Newton <ne...@yahoo.com>.
--- Adam Hardy <ah...@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.

> (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?

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.

> (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.

d.



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