You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stefano Corallo <st...@gmail.com> on 2009/05/27 08:53:47 UTC

Struts2 Interceptor

Hi all,

can an interceptor call an arbitraty action different from the action
requested by the client?

Suppose i've the interceptor "interceptor-router" placed in the stack and
the client call MyAction.action, when the interceptor intercept the call is
possible to 'redirect' the call to MyDifferentAction.action from the
interceptor?

I've seen that there is action chaining but this require to know at build
time the name of the actions i want to redirect to, but i know the name only
at runtime and


I hope i was clear :) sorry for my english.


--
Stefano Corallo

RE: Struts2 Interceptor

Posted by Martin Gainty <mg...@hotmail.com>.
you might possibly be breaking the one action class design of Struts

is there anything in the 2nd Action class which will not be accomodated by the first class?

right now its simple to look at the interceptor stack and determine which class is being called in what order..although technically possible to create any other class (Spring accomplishes this DI functionality thru Spring configured Factories) you would need a reason to justify a change in flow:

Specifically:
1a)Which updated/new attributes would the new Action class contain?
1b)Can we not accomodate the new Action attributes in the original Action Class?

2a)Which updated/new methods would the new Action class contain?
2b)Can we not accomodate these new Action methods in the original Action Class?

3a)Which context (element and attribute) params would be introduced by the new class?
3b)Can we not accomodate these new Context Params in the original Action Context?

What happens when this new class abends..how do you debug?

(my concern is obfuscation of flow or process can lead to confusion in implementation)

What say ye Musachy?

Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> From: steve@sjlt.co.uk
> To: user@struts.apache.org
> Subject: RE: Struts2 Interceptor
> Date: Wed, 27 May 2009 10:47:42 +0100
> 
> Hi Stefano,
> 
> This looks like an awkward design as you would go through half the
> interceptor stack expecting to call one action, and half the stack expecting
> to call a second action.
> 
> As an alternative could you do something like the following:-
> 
> Create class (or Interface) ReceivingAction with sub classes as the
> "actions" you want to assign dynamically.
> 
> Create a true action class ForwardingAction with a property ReceivingAction.
> 
> The interceptor can now dynamically create the class required (derived from
> / implementing ReceivingAction) and set it on the current action
> (ForwardingAction). It could also place the ReceivingAction instance on the
> ValueStack.
> 
> The main action methods you are interested in (e.g. execute) could simply
> forward to the ReceivingAction instance. You will need to be careful about
> interceptor order if you want to do things like set your parameter values on
> your ReceivingAction.
> 
> I haven't implemented this myself, although I have implemented all the
> techniques I have described. I'm fairly confident that this will achieve
> what you want.
> 
> Cheers,
> 
> Steve
> 
> -----Original Message-----
> From: Stefano Corallo [mailto:stefanorg@gmail.com] 
> Sent: 27 May 2009 07:54
> To: user@struts.apache.org
> Subject: Struts2 Interceptor
> 
> Hi all,
> 
> can an interceptor call an arbitraty action different from the action
> requested by the client?
> 
> Suppose i've the interceptor "interceptor-router" placed in the stack and
> the client call MyAction.action, when the interceptor intercept the call is
> possible to 'redirect' the call to MyDifferentAction.action from the
> interceptor?
> 
> I've seen that there is action chaining but this require to know at build
> time the name of the actions i want to redirect to, but i know the name only
> at runtime and
> 
> 
> I hope i was clear :) sorry for my english.
> 
> 
> --
> Stefano Corallo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Hotmail® goes with you. 
http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=TXT_TAGLM_WL_HM_Tutorial_Mobile1_052009

RE: Struts2 Interceptor

Posted by Steve <st...@sjlt.co.uk>.
Hi Stefano,

This looks like an awkward design as you would go through half the
interceptor stack expecting to call one action, and half the stack expecting
to call a second action.

As an alternative could you do something like the following:-

Create class (or Interface) ReceivingAction with sub classes as the
"actions" you want to assign dynamically.

Create a true action class ForwardingAction with a property ReceivingAction.

The interceptor can now dynamically create the class required (derived from
/ implementing ReceivingAction) and set it on the current action
(ForwardingAction). It could also place the ReceivingAction instance on the
ValueStack.

The main action methods you are interested in (e.g. execute) could simply
forward to the ReceivingAction instance. You will need to be careful about
interceptor order if you want to do things like set your parameter values on
your ReceivingAction.

I haven't implemented this myself, although I have implemented all the
techniques I have described. I'm fairly confident that this will achieve
what you want.

Cheers,

Steve

-----Original Message-----
From: Stefano Corallo [mailto:stefanorg@gmail.com] 
Sent: 27 May 2009 07:54
To: user@struts.apache.org
Subject: Struts2 Interceptor

Hi all,

can an interceptor call an arbitraty action different from the action
requested by the client?

Suppose i've the interceptor "interceptor-router" placed in the stack and
the client call MyAction.action, when the interceptor intercept the call is
possible to 'redirect' the call to MyDifferentAction.action from the
interceptor?

I've seen that there is action chaining but this require to know at build
time the name of the actions i want to redirect to, but i know the name only
at runtime and


I hope i was clear :) sorry for my english.


--
Stefano Corallo


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


Re: Struts2 Interceptor

Posted by Chris Pratt <th...@gmail.com>.
Yes, you can, though I don't really thing it's the right way to go.
Basically you use the body content of the <s:set> tag to set the variable to
the value of a scriplet expression like so:

<s:set value="fred"><%= myVar%></s:set>

Again, there are much better ways of coding modern web applications that
resorting to scriplets and I would certainly take the time to eradicate all
scriplets from your code as soon as you can, you will be happy you did.
  (*Chris*)

On Wed, May 27, 2009 at 1:01 AM, Qunhuan Mei <qm...@qm18.wanadoo.co.uk> wrote:

> Hello David and Chris,
>
> Thank you two very much indeed for your help.
>
> I have tried <s:set> tag with different scope and seems I can set a
> parameter to any value I want, but I can’t set it to the value/variable
> from
> jsp’s java code block, so I suppose <s:set> may not be applicable to my
> requirement. (or I must done something wrong somewhere!? Sorry I might not
> have presented the use case clearly in the first place)
>
> I’ll check the JSTL approach later – I suppose I should use its <set> tag
> (to a page scoped attribte?).
>
> Cheers,
>
> Qunhuan
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Hi,
> Sorry for my ignorance but could some one tell me how to access java code
> block's variable in jsp page. See the sample code below (say, from
> test.jsp)
>
> ...
> <%
>        boolean goAhead = true;
>        int counter = 0;
>        ...
> %>
>        <s:if test="goAhead">
>                ... <!-- go a head and do something -->
>        </s:if>
>        <s:if test="counter>0">
>                ... <!-- go a head and do something -->
>        </s:if>
> ...
>
> The reference of goAhead and counter within Struts' if tag is wrong. What
> should be the correct way to reference variable from java code block in
> this
> scenario?
>
> Many thanks in advance,
>
> Qunhuan
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: Struts2 Interceptor

Posted by Qunhuan Mei <qm...@qm18.wanadoo.co.uk>.
Hello David and Chris,

Thank you two very much indeed for your help. 

I have tried <s:set> tag with different scope and seems I can set a
parameter to any value I want, but I can’t set it to the value/variable from
jsp’s java code block, so I suppose <s:set> may not be applicable to my
requirement. (or I must done something wrong somewhere!? Sorry I might not
have presented the use case clearly in the first place)

I’ll check the JSTL approach later – I suppose I should use its <set> tag
(to a page scoped attribte?).

Cheers,

Qunhuan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

Hi,
Sorry for my ignorance but could some one tell me how to access java code
block's variable in jsp page. See the sample code below (say, from test.jsp)

...
<%
	boolean goAhead = true;
	int counter = 0;
	...
%>
	<s:if test="goAhead">
		... <!-- go a head and do something -->
	</s:if>					
	<s:if test="counter>0">
		... <!-- go a head and do something -->
	</s:if>					
...

The reference of goAhead and counter within Struts' if tag is wrong. What
should be the correct way to reference variable from java code block in this
scenario?

Many thanks in advance,

Qunhuan	




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


Re: Struts2 Interceptor

Posted by Stefano Corallo <st...@gmail.com>.
Yes i know that, very appreciate this clarification :)

--
Stefano Corallo


On Wed, May 27, 2009 at 5:25 PM, Dale Newfield <da...@newfield.org> wrote:

> Stefano Corallo wrote:
>
>> i think that this is the only one solution. Thanks guys for your reply.
>>
>
> If you don't have a base class for all of your actions, you might be able
> in the interceptor to get ahold of the ognl valueStack and set the value
> directly, then refer to #shortCircuitRedirectUrl (in the ognl dictionary
> rather than an attribute on action (top of ValueStack)).
>
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 Interceptor

Posted by Dale Newfield <da...@newfield.org>.
Martin Gainty wrote:
> //action class not implements ShortCircuitableValidator
> public class MyAction extends ActionSupport implements ShortCircuitableValidator 
> {
>     OgnlValueStack vs = new OgnlValueStack();

In an Action when I need the value stack I don't construct a new one but 
instead get it from the ActionContext:

ActionContext.getContext().getValueStack()

> would this work for shortCircuitRedirectUrl ?

If you want only some actions to be able to be short circuitable and 
wanted to set that on a class by class basis, then this interface sounds 
like a reasonable way to do so.  I believe the OP wanted to be able to 
have his logic work for *any* action.  Adding to his base class would 
work for any action that implements that base class, but not for a 
simple action that uses the struts default action class, which is why I 
suggested adding to the ognl context rather than setting a property on 
the action on top of the stack.  I don't believe the OP was asking about 
  something related to validation, but how to force users to a certain 
page/form ("Oh, we have something we want to force you to do before you 
do anything else").

-Dale

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


Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by mu...@aol.com.
Fernandes I had the same problem -- essentially I could not get it to work 
using the Convention plugin. Also, when you configure by xml you can't
have dev mode on.

The most I have gleaned off the internet, and there are people who 
should know better than me on this list the problem is to do with
the scanning process as the framework scans for action classes.

Anyone who knows more, chime in.
Cheers
Chris



-----Original Message-----
From: Fernandes Celinio <cf...@sopragroup.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Wed, 27 May 2009 12:58 pm
Subject: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0



Hi,
Is there a problem when using the Convention plug-in with Jboss 5.1.0 ?
I mean there is no struts.xml file., the mapping is defined in the
Action classes, through the use of annotations such as :

 @Actions({
             @Action(value="/myFirstPath",
             results={@Result(name="success",
location="/here/first.jsp")}
             ),
             @Action(value="/mySecondPath",
             results={@Result(name="success",
location="/here/second.jsp")}
             )
    })

Http://localhost:8080/myFirstPath 
Gives me the following error :
HTTP Status 404 - There is no Action mapped for namespace / and action
name myFirstPath.

Http://localhost:8080/mySecondPath
Gives me the following error :
HTTP Status 404 - There is no Action mapped for namespace / and action
name mySecondPath.

I know it works well with the Tomcat server.

Is there a problem with Jboss ? Something else to configure ?

Thanks for helping.
Celinio

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


Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by mu...@aol.com.
There is something new -- something to do with virtual classpaths that
makes JBoss 5 reject apps with dev mode on or with the Convention
plugin active while JBoss 4 accepts them.
Chris


-----Original Message-----
From: Lukasz Lenart <lu...@googlemail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Wed, 27 May 2009 4:51 pm
Subject: Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0



2009/5/27  <mu...@aol.com>:
> Me again: here is a link with a discussion. Don't hold your breath as
> it does not give a work around.
> http://www.nabble.com/Problems-using-Struts2-on-JBoss-5.0.1GA-td22969807.html

Does it mean it solves your issue? Or there there is something new
regarding JBoss 5.1?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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



Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/27  <mu...@aol.com>:
> Me again: here is a link with a discussion. Don't hold your breath as
> it does not give a work around.
> http://www.nabble.com/Problems-using-Struts2-on-JBoss-5.0.1GA-td22969807.html

Does it mean it solves your issue? Or there there is something new
regarding JBoss 5.1?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by mu...@aol.com.
Me again: here is a link with a discussion. Don't hold your breath as
it does not give a work around.
http://www.nabble.com/Problems-using-Struts2-on-JBoss-5.0.1GA-td22969807.html
Chris


-----Original Message-----
From: Fernandes Celinio <cf...@sopragroup.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Wed, 27 May 2009 1:06 pm
Subject: RE: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0



Yes, I did and it works.
So i am assuming there is a problem with Jboss. I have not checked the logs yet.
-----Message d'origine-----
e : Lukasz Lenart [mailto:lukasz.lenart@googlemail.com] 
nvoyé : mercredi 27 mai 2009 19:02
 : Struts Users Mailing List
bjet : Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0
2009/5/27 Fernandes Celinio <cf...@sopragroup.com>:
 I know it works well with the Tomcat server.
JBoss is using Tomcat to serve Java web applications, did you try deploy the 
ame application to standalone Tomcat?

egards
-
ukasz
ttp://www.lenart.org.pl/
---------------------------------------------------------------------
o unsubscribe, e-mail: user-unsubscribe@struts.apache.org
or additional commands, e-mail: user-help@struts.apache.org

--------------------------------------------------------------------
o unsubscribe, e-mail: user-unsubscribe@struts.apache.org
or additional commands, e-mail: user-help@struts.apache.org


RE: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by Fernandes Celinio <cf...@sopragroup.com>.
Yes, I did and it works.

So i am assuming there is a problem with Jboss. I have not checked the logs yet.

-----Message d'origine-----
De : Lukasz Lenart [mailto:lukasz.lenart@googlemail.com] 
Envoyé : mercredi 27 mai 2009 19:02
À : Struts Users Mailing List
Objet : Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

2009/5/27 Fernandes Celinio <cf...@sopragroup.com>:
> I know it works well with the Tomcat server.

JBoss is using Tomcat to serve Java web applications, did you try deploy the same application to standalone Tomcat?


Regards
--
Lukasz
http://www.lenart.org.pl/

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


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


Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by mu...@aol.com.
Lukasz, it is JBoss specific -- actually JBoss 5. Apps that
work on JBoss 4 with the Convention Plugin fail with
JBoss 5.

I can post the specific error messages when I get home next
week (I am in Stockholm without my code.
Cheers
Chris


-----Original Message-----
From: Lukasz Lenart <lu...@googlemail.com>
To: Struts Users Mailing List <us...@struts.apache.org>
Sent: Wed, 27 May 2009 1:02 pm
Subject: Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0



2009/5/27 Fernandes Celinio <cf...@sopragroup.com>:
> I know it works well with the Tomcat server.

JBoss is using Tomcat to serve Java web applications, did you try
deploy the same application to standalone Tomcat?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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



Re: [Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/5/27 Fernandes Celinio <cf...@sopragroup.com>:
> I know it works well with the Tomcat server.

JBoss is using Tomcat to serve Java web applications, did you try
deploy the same application to standalone Tomcat?


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


[Struts 2.1.6] Convention plug-in not working with Jboss 5.1.0

Posted by Fernandes Celinio <cf...@sopragroup.com>.
Hi,
Is there a problem when using the Convention plug-in with Jboss 5.1.0 ?
I mean there is no struts.xml file., the mapping is defined in the
Action classes, through the use of annotations such as :

 @Actions({
             @Action(value="/myFirstPath",
             results={@Result(name="success",
location="/here/first.jsp")}
             ),
             @Action(value="/mySecondPath",
             results={@Result(name="success",
location="/here/second.jsp")}
             )
    })

Http://localhost:8080/myFirstPath 
Gives me the following error :
HTTP Status 404 - There is no Action mapped for namespace / and action
name myFirstPath.

Http://localhost:8080/mySecondPath
Gives me the following error :
HTTP Status 404 - There is no Action mapped for namespace / and action
name mySecondPath.

I know it works well with the Tomcat server.

Is there a problem with Jboss ? Something else to configure ?

Thanks for helping.
Celinio

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


RE: Struts2 Interceptor

Posted by Martin Gainty <mg...@hotmail.com>.
hello dale-
in my xwork discoveries i came upon the ShortCircuitableValidator defined as
/** Copyright (c) 2002-2006 by OpenSymphony All rights reserved.*/
package com.opensymphony.xwork.validator;
/**
 * This interface should be implemented by validators that can short-circuit the validator queue that it is in @author Mark Woon
 */
public interface ShortCircuitableValidator {
    /*** Sets whether this field validator should short circuit the validator queue
     * it's in if validation fails
     * @param shortcircuit true if this field validator should short circuit on
     *                     failure, false otherwise
     */
    public void setShortCircuit(boolean shortcircuit);

    /*** Gets whether this field validator should short circuit the validator queue
     * it's in if validation fails.
     * @return true if this field validator should short circuit on failure,
     *         false otherwise*/
    public boolean isShortCircuit();
}

//action class not implements ShortCircuitableValidator
public class MyAction extends ActionSupport implements ShortCircuitableValidator 
{
    OgnlValueStack vs = new OgnlValueStack();
    String isBogus =(isShortCircuit()==true)?"true":"false";
        try {
            vs.setValue("shortCircuitRedirectUrl", isBogus, 1);
        }
         catch (OgnlException e) 
        {
          log.debug("OgnlException happened here"+e.getMessage());
         }
}

would this work for shortCircuitRedirectUrl ?
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Wed, 27 May 2009 11:25:47 -0400
> From: dale@newfield.org
> To: user@struts.apache.org
> Subject: Re: Struts2 Interceptor
> 
> Stefano Corallo wrote:
> > i think that this is the only one solution. Thanks guys for your reply.
> 
> If you don't have a base class for all of your actions, you might be 
> able in the interceptor to get ahold of the ognl valueStack and set the 
> value directly, then refer to #shortCircuitRedirectUrl (in the ognl 
> dictionary rather than an attribute on action (top of ValueStack)).
> 
> -Dale
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Insert movie times and more without leaving Hotmail®.
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009

Re: Struts2 Interceptor

Posted by Dale Newfield <da...@newfield.org>.
Stefano Corallo wrote:
> i think that this is the only one solution. Thanks guys for your reply.

If you don't have a base class for all of your actions, you might be 
able in the interceptor to get ahold of the ognl valueStack and set the 
value directly, then refer to #shortCircuitRedirectUrl (in the ognl 
dictionary rather than an attribute on action (top of ValueStack)).

-Dale

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


Re: Struts2 Interceptor

Posted by Stefano Corallo <st...@gmail.com>.
Hi Dale,

i think that this is the only one solution. Thanks guys for your reply.

--
Stefano Corallo


On Wed, May 27, 2009 at 4:59 PM, Dale Newfield <da...@newfield.org> wrote:

> Stefano Corallo wrote:
>
>> I know the global result, but is unusefull for this purpose. The problem
>> is
>> that the actions that i want to call is knew at runtime cause the
>> interceptor at init time scan classes with certain annotations and i want
>> to
>> forward to those actions so i can't put the result in struts.xml because i
>> can't know what action to call.
>>
>
> If you make the global result "shortCircuitRedirect" redirect to
> %{shortCircuitRedirectUrl}, add that member and getter to your BaseAction
> class, and have your interceptor both set the Url on the action, then return
> the global result name, you'll be able to do what you ask.
>
> -Dale
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 Interceptor

Posted by Dale Newfield <da...@newfield.org>.
Stefano Corallo wrote:
> I know the global result, but is unusefull for this purpose. The problem is
> that the actions that i want to call is knew at runtime cause the
> interceptor at init time scan classes with certain annotations and i want to
> forward to those actions so i can't put the result in struts.xml because i
> can't know what action to call.

If you make the global result "shortCircuitRedirect" redirect to 
%{shortCircuitRedirectUrl}, add that member and getter to your 
BaseAction class, and have your interceptor both set the Url on the 
action, then return the global result name, you'll be able to do what 
you ask.

-Dale

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


Re: Struts2 Interceptor

Posted by Chris Pratt <th...@gmail.com>.
You can still use the Global Result, just set the global results value to an
OGNL expression.  This limits the places you can use the interceptor to
actions that can fill the OGNL expression, but you could handle that with a
common base class if you really want to go down this path.  I don't think
you really want to just call another Action (which is totally doable, but it
won't have any of it's data since it's interceptor stack won't have been
run).  Basically what you want is a method on your common base class like:

method getNextAction () {
  return "next";
}

And a global result like:

<result name="gtfo" type="redirect-action">${nextAction}</result>

I think you would be better off sticking to the tried and true patterns that
the Struts team has designed the system to work with, but if you must, this
should work.
  (*Chris*)

On Wed, May 27, 2009 at 2:17 AM, Stefano Corallo <st...@gmail.com>wrote:

> Hi Criss,
> thanks for your reply.
>
> I know the global result, but is unusefull for this purpose. The problem is
> that the actions that i want to call is knew at runtime cause the
> interceptor at init time scan classes with certain annotations and i want
> to
> forward to those actions so i can't put the result in struts.xml because i
> can't know what action to call.
>
> So my question is: the only way for an action to redirect to another action
> is via redirect-action-result ? like described in:
> http://struts.apache.org/2.x/docs/redirect-action-result.html
> Maybe putting in the annotation the information to call the action i want
> ....
>
> --
> Stefano Corallo
>
>
> On Wed, May 27, 2009 at 9:07 AM, Chris Pratt <thechrispratt@gmail.com
> >wrote:
>
> > Sort of.  The way that I've achieved something similar to what you seem
> to
> > be asking is to define a bunch of Global Results in struts.xml that
> define
> > common actions that the interceptors may need to invoke (like
> > reset-password
> > or invalid-input), then instead of chaining to the action in the
> > interceptor, just return the name of the global result and you've
> > effectively called that action.
> >  (*Chris*)
> >
> > On Tue, May 26, 2009 at 11:53 PM, Stefano Corallo <stefanorg@gmail.com
> > >wrote:
> >
> > > Hi all,
> > >
> > > can an interceptor call an arbitraty action different from the action
> > > requested by the client?
> > >
> > > Suppose i've the interceptor "interceptor-router" placed in the stack
> and
> > > the client call MyAction.action, when the interceptor intercept the
> call
> > is
> > > possible to 'redirect' the call to MyDifferentAction.action from the
> > > interceptor?
> > >
> > > I've seen that there is action chaining but this require to know at
> build
> > > time the name of the actions i want to redirect to, but i know the name
> > > only
> > > at runtime and
> > >
> > >
> > > I hope i was clear :) sorry for my english.
> > >
> > >
> > > --
> > > Stefano Corallo
> > >
> >
>

Re: Struts2 Interceptor

Posted by Stefano Corallo <st...@gmail.com>.
Hi Criss,
thanks for your reply.

I know the global result, but is unusefull for this purpose. The problem is
that the actions that i want to call is knew at runtime cause the
interceptor at init time scan classes with certain annotations and i want to
forward to those actions so i can't put the result in struts.xml because i
can't know what action to call.

So my question is: the only way for an action to redirect to another action
is via redirect-action-result ? like described in:
http://struts.apache.org/2.x/docs/redirect-action-result.html
Maybe putting in the annotation the information to call the action i want
....

--
Stefano Corallo


On Wed, May 27, 2009 at 9:07 AM, Chris Pratt <th...@gmail.com>wrote:

> Sort of.  The way that I've achieved something similar to what you seem to
> be asking is to define a bunch of Global Results in struts.xml that define
> common actions that the interceptors may need to invoke (like
> reset-password
> or invalid-input), then instead of chaining to the action in the
> interceptor, just return the name of the global result and you've
> effectively called that action.
>  (*Chris*)
>
> On Tue, May 26, 2009 at 11:53 PM, Stefano Corallo <stefanorg@gmail.com
> >wrote:
>
> > Hi all,
> >
> > can an interceptor call an arbitraty action different from the action
> > requested by the client?
> >
> > Suppose i've the interceptor "interceptor-router" placed in the stack and
> > the client call MyAction.action, when the interceptor intercept the call
> is
> > possible to 'redirect' the call to MyDifferentAction.action from the
> > interceptor?
> >
> > I've seen that there is action chaining but this require to know at build
> > time the name of the actions i want to redirect to, but i know the name
> > only
> > at runtime and
> >
> >
> > I hope i was clear :) sorry for my english.
> >
> >
> > --
> > Stefano Corallo
> >
>

Re: Struts2 Interceptor

Posted by Chris Pratt <th...@gmail.com>.
Sort of.  The way that I've achieved something similar to what you seem to
be asking is to define a bunch of Global Results in struts.xml that define
common actions that the interceptors may need to invoke (like reset-password
or invalid-input), then instead of chaining to the action in the
interceptor, just return the name of the global result and you've
effectively called that action.
  (*Chris*)

On Tue, May 26, 2009 at 11:53 PM, Stefano Corallo <st...@gmail.com>wrote:

> Hi all,
>
> can an interceptor call an arbitraty action different from the action
> requested by the client?
>
> Suppose i've the interceptor "interceptor-router" placed in the stack and
> the client call MyAction.action, when the interceptor intercept the call is
> possible to 'redirect' the call to MyDifferentAction.action from the
> interceptor?
>
> I've seen that there is action chaining but this require to know at build
> time the name of the actions i want to redirect to, but i know the name
> only
> at runtime and
>
>
> I hope i was clear :) sorry for my english.
>
>
> --
> Stefano Corallo
>