You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chris Pratt <th...@gmail.com> on 2007/07/05 08:56:01 UTC

[S2] Default Action

I am trying to figure out how to set the default class that is executed when
a class is not specified on an <action> declaration.  When you specify
something like:

<action name="home">
  <result>/home.jsp</result>
</action>

Struts automatically runs com.opensymphony.xwork2.ActionSupport.  But I am
trying to figure out how to accomplish this:

<action name="home">
  <param name="role">user</param>
  <result>/home.jsp</result>
</action>

Since ActionSupport doesn't have a setRole method, this won't work out of
the box, so I created a simple extension of ActionSupport to hold the role
value.  After a bit of googling, I got the idea that this should work:

<action name="default" class="my.package.BaseAction"/>

<default-action-ref name="default"/>

but that doesn't seem to do the job.  Is it possible?  Is there another way
to specify this type of information on a per Action basis?  Any insights
would be appreciated.
  (*Chris*)

Re: [S2] Default Action

Posted by Chris Pratt <th...@gmail.com>.
For anybody following this thread, I finally answered my own question by
searching through the code.  There is an undocumented struts.xml element
that will allow you to redefine the default Action class that gets called
when no class is specified on an action definition.  It's not in the DTD,
but it works because
com.opensymphony.xwork2\config\providers\XmlConfigurationProvider.loadDefaultClassRefchecks
for it.

<default-class-ref class="com.anodyzed.portal.controller.BaseAction"/>

  (*Chris*)

On 7/6/07, Chris Pratt <th...@gmail.com> wrote:
>
> I think we're both on the same page, but according to some things I've
> read on the internet, I should be able to change the default class.  But
> when I try what they suggest, it doesn't work.  I'm hoping someone here
> knows for sure whether it can be done or not.
>
> If not, I'd like to suggest it as a feature for the next version.
>   (*Chris*)
>
> On 7/6/07, yitzle < yitzle@users.sourceforge.net> wrote:
> >
> > I think the trouble is you want are specifying the action but not its
> > matching class, in which case it uses the default class which can not
> > be changed.
> >
> > I'm suggesting that you don't have the action in the xml file and have
> > it use the default action for which you had specified the class.
> > <action name="Default" class="package.base">
> >
> > Inside base.execute() you examine the URL and set the role.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

Re: [S2] Default Action

Posted by Chris Pratt <th...@gmail.com>.
I think we're both on the same page, but according to some things I've read
on the internet, I should be able to change the default class.  But when I
try what they suggest, it doesn't work.  I'm hoping someone here knows for
sure whether it can be done or not.

If not, I'd like to suggest it as a feature for the next version.
  (*Chris*)

On 7/6/07, yitzle <yi...@users.sourceforge.net> wrote:
>
> I think the trouble is you want are specifying the action but not its
> matching class, in which case it uses the default class which can not
> be changed.
>
> I'm suggesting that you don't have the action in the xml file and have
> it use the default action for which you had specified the class.
> <action name="Default" class="package.base">
>
> Inside base.execute() you examine the URL and set the role.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Default Action

Posted by yitzle <yi...@users.sourceforge.net>.
I think the trouble is you want are specifying the action but not its
matching class, in which case it uses the default class which can not
be changed.

I'm suggesting that you don't have the action in the xml file and have
it use the default action for which you had specified the class.
<action name="Default" class="package.base">

Inside base.execute() you examine the URL and set the role.

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


Re: [S2] Default Action

Posted by Chris Pratt <th...@gmail.com>.
That's more or less what I'm trying to do.  Instead of using the default
execute(), I can use the default setRole() by specifying the <param
name="role"> element.  That I can't figure out is how to define the default
action.
  (*Chris*)

On 7/6/07, yitzle <yi...@users.sourceforge.net> wrote:
>
> Oops. I misunderstood your question.
> Maybe use a default action... If there is a way to 'peek' at the URL
> requested, maybe you can set the role in the default execute() based
> on that.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Default Action

Posted by yitzle <yi...@users.sourceforge.net>.
Oops. I misunderstood your question.
Maybe use a default action... If there is a way to 'peek' at the URL
requested, maybe you can set the role in the default execute() based
on that.

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


Re: [S2] Default Action

Posted by Chris Pratt <th...@gmail.com>.
Where would I get the value from?
  (*Chris*)

On 7/5/07, yitzle <yi...@users.sourceforge.net> wrote:
>
> I'm not sure what you are trying to do, but each action calls an execute()
> Couldn't you set the role value in the execute()?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] Default Action

Posted by yitzle <yi...@users.sourceforge.net>.
I'm not sure what you are trying to do, but each action calls an execute()
Couldn't you set the role value in the execute()?

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