You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alexander Baetz <ba...@arcor.de> on 2008/10/28 11:16:50 UTC

How to putt objects on the valuestack from INSIDE an action?

Hi,

currently i'm trying to use my own Class to store configuration data for 
my application.
To access the options from within the jsp page i want to use the struts 
2 value stack. I somehow like the stack more than i like the session.

My problem is the following:
i can put objects in the session, but how do i put one on the stack so i 
can find it with something like:
value="#mySettings" ?

my current SettingsInterceptor looks like this (and doesnt work):

        // get the action on which the interceptor is fired
        Object action = actionInvocation.getAction();
        // get the value stack
        ValueStack stack = 
actionInvocation.getInvocationContext().getValueStack();
        // try to retrieve the bean
        SettingsBean settings = (SettingsBean) 
stack.findValue("mySettings");
        if (settings == null) {
            settings = new SettingsBean();
            stack.set("mySettings", settings);
        }
        try {
            ((SettingsBeanAware) action).setPageSettingsBean(settings);
        } catch (Exception e) {
        }
        return actionInvocation.invoke();

Greetings,
Alexander

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


Re: How to putt objects on the valuestack from INSIDE an action?

Posted by "matt.payne" <ma...@gmail.com>.
You should probably be doing this from an interceptor.

Matt

Alexander Baetz wrote:
> 
> Hi,
> 
> currently i'm trying to use my own Class to store configuration data for 
> my application.
> To access the options from within the jsp page i want to use the struts 
> 2 value stack. I somehow like the stack more than i like the session.
> 
> My problem is the following:
> i can put objects in the session, but how do i put one on the stack so i 
> can find it with something like:
> value="#mySettings" ?
> 
> my current SettingsInterceptor looks like this (and doesnt work):
> 
>         // get the action on which the interceptor is fired
>         Object action = actionInvocation.getAction();
>         // get the value stack
>         ValueStack stack = 
> actionInvocation.getInvocationContext().getValueStack();
>         // try to retrieve the bean
>         SettingsBean settings = (SettingsBean) 
> stack.findValue("mySettings");
>         if (settings == null) {
>             settings = new SettingsBean();
>             stack.set("mySettings", settings);
>         }
>         try {
>             ((SettingsBeanAware) action).setPageSettingsBean(settings);
>         } catch (Exception e) {
>         }
>         return actionInvocation.invoke();
> 
> Greetings,
> Alexander
> 
> ---------------------------------------------------------------------
> 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/How-to-putt-objects-on-the-valuestack-from-INSIDE-an-action--tp20204481p20210627.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: How to putt objects on the valuestack from INSIDE an action?

Posted by hernan gonzalez <hg...@gmail.com>.
A suggestion, which might or not be adequate for your case:
If  every action/jsp of your webapplication share that behaviour, and
if your actions
presently just extend ActionSupport, you might want to change that so that they
extend instead a MySiteAction class (which extends ActionSupport and implements
ServletRequestAware) with a getter for that object kept in the session.

Hernán J. González
http://hjg.com.ar/


On Wed, Oct 29, 2008 at 8:46 AM, Alexander Baetz
<ba...@arcor.de> wrote:
> I guess i should add explanation.
>
> i want to save an object permanently on the value stack.
> In my case this object holds many informations that configure my pages
> (loginuserid.......). It is created inside my loginAction.
> I can get it from an action with a get-Method, but this object is permanent
> and doesnt matter for any action beside login/logout. But the jsp uses it
> every time.
>
> I could put this object into the session (which i currently do). But i like
> the value stack, and prefere lines like "#Settings.loginUser.id" instead of
> "#session.settings.loginuser.id"
>
> Hope i could explain my "problem"
>
> Greetings,
> Laures
>
> Sébastien Domergue schrieb:
>>

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


Re: How to putt objects on the valuestack from INSIDE an action?

Posted by Alexander Baetz <ba...@arcor.de>.
I guess i should add explanation.

i want to save an object permanently on the value stack.
In my case this object holds many informations that configure my pages 
(loginuserid.......). It is created inside my loginAction.
I can get it from an action with a get-Method, but this object is 
permanent and doesnt matter for any action beside login/logout. But the 
jsp uses it every time.

I could put this object into the session (which i currently do). But i 
like the value stack, and prefere lines like "#Settings.loginUser.id" 
instead of "#session.settings.loginuser.id"

Hope i could explain my "problem"

Greetings,
Laures

Sébastien Domergue schrieb:
> Hi,
>
> reading your mail, it seems to me that you want te redevelop what 
> Struts 2 can already do. When you put a getter in your action, you can 
> access to your attribute in the jsp like you seems to want to. I can't 
> understand why you want to put another Interceptor. If it is to set 
> always the same value, you could use hierarchy to have a class that 
> deal with all of the common attributes and all of the others should 
> inherit from it and implements their owns attributes.
>
> If it is a misunderstand from me, sorry...
>
> regards
>
> Sébastien
>
> Alexander Baetz a écrit :
>> Hi,
>>
>> currently i'm trying to use my own Class to store configuration data 
>> for my application.
>> To access the options from within the jsp page i want to use the 
>> struts 2 value stack. I somehow like the stack more than i like the 
>> session.
>>
>> My problem is the following:
>> i can put objects in the session, but how do i put one on the stack 
>> so i can find it with something like:
>> value="#mySettings" ?
>>
>> my current SettingsInterceptor looks like this (and doesnt work):
>>
>>        // get the action on which the interceptor is fired
>>        Object action = actionInvocation.getAction();
>>        // get the value stack
>>        ValueStack stack = 
>> actionInvocation.getInvocationContext().getValueStack();
>>        // try to retrieve the bean
>>        SettingsBean settings = (SettingsBean) 
>> stack.findValue("mySettings");
>>        if (settings == null) {
>>            settings = new SettingsBean();
>>            stack.set("mySettings", settings);
>>        }
>>        try {
>>            ((SettingsBeanAware) action).setPageSettingsBean(settings);
>>        } catch (Exception e) {
>>        }
>>        return actionInvocation.invoke();
>>
>> Greetings,
>> Alexander
>>
>> ---------------------------------------------------------------------
>> 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


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


Re: How to putt objects on the valuestack from INSIDE an action?

Posted by Sébastien Domergue <se...@c-s.fr>.
Hi,

reading your mail, it seems to me that you want te redevelop what Struts 
2 can already do. When you put a getter in your action, you can access 
to your attribute in the jsp like you seems to want to. I can't 
understand why you want to put another Interceptor. If it is to set 
always the same value, you could use hierarchy to have a class that deal 
with all of the common attributes and all of the others should inherit 
from it and implements their owns attributes.

If it is a misunderstand from me, sorry...

regards

S�bastien

Alexander Baetz a �crit :
> Hi,
>
> currently i'm trying to use my own Class to store configuration data 
> for my application.
> To access the options from within the jsp page i want to use the 
> struts 2 value stack. I somehow like the stack more than i like the 
> session.
>
> My problem is the following:
> i can put objects in the session, but how do i put one on the stack so 
> i can find it with something like:
> value="#mySettings" ?
>
> my current SettingsInterceptor looks like this (and doesnt work):
>
>        // get the action on which the interceptor is fired
>        Object action = actionInvocation.getAction();
>        // get the value stack
>        ValueStack stack = 
> actionInvocation.getInvocationContext().getValueStack();
>        // try to retrieve the bean
>        SettingsBean settings = (SettingsBean) 
> stack.findValue("mySettings");
>        if (settings == null) {
>            settings = new SettingsBean();
>            stack.set("mySettings", settings);
>        }
>        try {
>            ((SettingsBeanAware) action).setPageSettingsBean(settings);
>        } catch (Exception e) {
>        }
>        return actionInvocation.invoke();
>
> Greetings,
> Alexander
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>