I think it could be a simple and elegant change to support a generic toString() 
functionality on the execute return object.  Currently the 
DefaultActionInvocation calls the execute method and gets an Object back.  It 
then checks if the object is instanceof Result, if so it uses it as the result, 
otherwise it assumes it's a String and later does a lookup of the Result that 
maps to the String.

I would propose the following change.  Change the 
DefaultActionInvocation.invokeAction method to do

            if (methodResult instanceof Result) {
                this.result = (Result) methodResult;
                return null;
            } else {
                return methodResult == null ? null : methodResult.toString();
            }

Additionally it might be good if an interface Action<T> existed that extended 
the existing Action interface.

Darren

-----Original Message-----
From: Adam Hardy [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 20, 2007 12:38 PM
To: Struts Developers List
Subject: Re: struts action results

Chris Pratt on 20/09/07 17:20, wrote:
> On 9/20/07, Adam Hardy <[EMAIL PROTECTED]> wrote:
>> Would it be a big deal to change 
>> com.opensymphony.xwork2.DefaultActionInvocation
>> to allow my Action to return an enumeration instead of a string?
>>
> 
> How about creating a subclass of ActionSupport that has it's own
> execute style method, we could call it perform, that returns an
> enumeration, then by extension all your Actions could have the
> behaviour you're looking for.  Something like:
> 
> public class EnumActionSupport extends ActionSupport {
> 
>   public abstract Enum perform();
> 
>   public String execute () {
>     return perform().toString();
>   } //execute
> 
> } //*EnumActionSupport

Of course I could do that too. At the moment I just return 
MyEnum.WHATEVER.toString() so the question is, which is more elegant: using an 
extra superclass, using .toString() on every return statement or changing the 
ActionInvocation?

I guess you get questions like this on the dev list all the time, people asking 
for tweaks and bells and whistles. But I can't see any disadvantage if the 
ActionInvocation called toString() instead of trying to cast it. Obviously I'm 
curious to know if there are disadvantages to it as well.

Regards
Adam



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to