You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Adam Hardy <ah...@cyberspaceroad.com> on 2007/09/20 18:13:01 UTC

struts action results

Would it be a big deal to change com.opensymphony.xwork2.DefaultActionInvocation
to allow my Action to return an enumeration instead of a string?

I tried it myself but the code wants to cast my Enumeration to a string, rather
than call .toString():


             	return (String) methodResult;


This throws a ClassCastException. However this wouldn't:


             	return methodResult.toString();


but would have presumably the same effect.

The reason I ask is that I can then code my Action more elegantly with
enumerations instead of strings for return values.

Regards
Adam


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


Re: struts action results

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Chris Pratt on 20/09/07 17:20, wrote:
> On 9/20/07, Adam Hardy <ah...@cyberspaceroad.com> 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: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: struts action results

Posted by Chris Pratt <th...@gmail.com>.
On 9/20/07, Adam Hardy <ah...@cyberspaceroad.com> 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

  (*Chris*)

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