You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Prasad Mangina <pr...@constructiondeal.com> on 2009/02/09 10:59:51 UTC

Struts 2.1.6 - custom interceptor

Dear All,
 
i have programmed a simple (custom) interceptor.
 
....placed logic in post action invocation.
 
public String doIntercept(ActionInvocation invocation) throws Exception {

    Object action = invocation.getAction();

    String ret = invocation.invoke();

    if (action instanceof MyAware) {

            ((MyAware) action).callme();

    }

    return ret;

}

....in Action's "callme()" method, I am setting action's var (this var has
getter and setter).

In my velocity vm file, I am accessing this action's var.

$myvar

By default, the action's property would be placed in valuestack and, could
be accessed from velocity page.

Hmmm, this is not showing up in the velocity page.

If, this is in pre action invocation, $myvar 's value gets displayed . Only,
when this goes into post action invocation, it is not showing up...

Any clues?

Regards,
Prasad

 


RE: Struts 2.1.6 - custom interceptor

Posted by Prasad M <pm...@gmail.com>.
Dear Greg Lindholm,

Thanks so much. I could make it work with preresultlistener. Really Cool.

Dear Lukasz Lenar,

Thanks so much. So, I understand that the result has been created before it
reaches the post invoke in interceptor.


But, I still wonder with a question as to why this cannot happen simply? I
mean, without a preresultlistener.



Ok. My next question is as follows (in further to the same post invoke in
interceptor):
(I want to illustrate with a simple example)

1) I want to decorate a string property of action.
2) The interceptor will add for example, "$" before the value of property.
3*) I am against adding any method in action. No logic will go in action
class.
4) My interceptor will pick up the action property, modify it in invoke()
method, itself.
5) So, when I want to decorate, I add my interceptor in struts.xml for this
action.
6) My interceptor needs to pick up a property from action and decorate it.
(In post action invoke())

Please let me know.

Thanks so much.

Regards,
Prasad

-----Original Message-----
From: Greg Lindholm [mailto:glindholm@yahoo.com] 
Sent: Monday, February 09, 2009 11:47 PM
To: user@struts.apache.org
Subject: Re: Struts 2.1.6 - custom interceptor


Take a look at PreResultListener

http://struts.apache.org/2.x/docs/preresultlistener.html


Lukasz Lenart wrote:
> 
> 2009/2/9 Prasad Mangina <pr...@constructiondeal.com>:
>> Dear All,
>>
>> i have programmed a simple (custom) interceptor.
>>
>> ....placed logic in post action invocation.
>>
>> public String doIntercept(ActionInvocation invocation) throws Exception {
>>
>>    Object action = invocation.getAction();
>>
>>    String ret = invocation.invoke();
>>
>>    if (action instanceof MyAware) {
>>
>>            ((MyAware) action).callme();
>>
>>    }
>>
>>    return ret;
>>
>> }
>>
>> ....in Action's "callme()" method, I am setting action's var (this var
>> has
>> getter and setter).
>>
>> In my velocity vm file, I am accessing this action's var.
>>
>> $myvar
>>
>> By default, the action's property would be placed in valuestack and,
>> could
>> be accessed from velocity page.
>>
>> Hmmm, this is not showing up in the velocity page.
>>
>> If, this is in pre action invocation, $myvar 's value gets displayed .
>> Only,
>> when this goes into post action invocation, it is not showing up...
>>
>> Any clues?
> 
> After you call invoke(), result (jsp, vm, etc) was already generated,
> that because your call to callme() is not working
> 
> 
> 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
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Struts-2.1.6---custom-interceptor-tp21910825p21918703.
html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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 - custom interceptor

Posted by Greg Lindholm <gl...@yahoo.com>.
Take a look at PreResultListener

http://struts.apache.org/2.x/docs/preresultlistener.html


Lukasz Lenart wrote:
> 
> 2009/2/9 Prasad Mangina <pr...@constructiondeal.com>:
>> Dear All,
>>
>> i have programmed a simple (custom) interceptor.
>>
>> ....placed logic in post action invocation.
>>
>> public String doIntercept(ActionInvocation invocation) throws Exception {
>>
>>    Object action = invocation.getAction();
>>
>>    String ret = invocation.invoke();
>>
>>    if (action instanceof MyAware) {
>>
>>            ((MyAware) action).callme();
>>
>>    }
>>
>>    return ret;
>>
>> }
>>
>> ....in Action's "callme()" method, I am setting action's var (this var
>> has
>> getter and setter).
>>
>> In my velocity vm file, I am accessing this action's var.
>>
>> $myvar
>>
>> By default, the action's property would be placed in valuestack and,
>> could
>> be accessed from velocity page.
>>
>> Hmmm, this is not showing up in the velocity page.
>>
>> If, this is in pre action invocation, $myvar 's value gets displayed .
>> Only,
>> when this goes into post action invocation, it is not showing up...
>>
>> Any clues?
> 
> After you call invoke(), result (jsp, vm, etc) was already generated,
> that because your call to callme() is not working
> 
> 
> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2.1.6---custom-interceptor-tp21910825p21918703.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Struts 2.1.6 - custom interceptor

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/2/9 Prasad Mangina <pr...@constructiondeal.com>:
> Dear All,
>
> i have programmed a simple (custom) interceptor.
>
> ....placed logic in post action invocation.
>
> public String doIntercept(ActionInvocation invocation) throws Exception {
>
>    Object action = invocation.getAction();
>
>    String ret = invocation.invoke();
>
>    if (action instanceof MyAware) {
>
>            ((MyAware) action).callme();
>
>    }
>
>    return ret;
>
> }
>
> ....in Action's "callme()" method, I am setting action's var (this var has
> getter and setter).
>
> In my velocity vm file, I am accessing this action's var.
>
> $myvar
>
> By default, the action's property would be placed in valuestack and, could
> be accessed from velocity page.
>
> Hmmm, this is not showing up in the velocity page.
>
> If, this is in pre action invocation, $myvar 's value gets displayed . Only,
> when this goes into post action invocation, it is not showing up...
>
> Any clues?

After you call invoke(), result (jsp, vm, etc) was already generated,
that because your call to callme() is not working


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