You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by John Smith <de...@gmail.com> on 2008/06/24 09:57:23 UTC

Newbie Q: How to set session object parameters in struts.xml

Hello,

Is it possible to set session objects inside and action and access the
session object in another action without explicitly retrieving the
session object?

Thanks,
J

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


Re: Newbie Q: How to set session object parameters in struts.xml

Posted by Lukasz Lenart <lu...@googlemail.com>.
To be clear with previous post, first try to parse data then put it on
the stack.


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: Newbie Q: How to set session object parameters in struts.xml

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

I misunderstood you ;-) I spent some time to find solution but right
now it isn't possible because of StaticParametersInterceptor. Look at
the code below

            for (Iterator iterator = parameters.entrySet().iterator();
                 iterator.hasNext();) {
                Map.Entry entry = (Map.Entry) iterator.next();
                stack.setValue(entry.getKey().toString(),
entry.getValue()); // exception here if you try something like you
                Object val = entry.getValue();
                if (parse && val instanceof String) {
                    val = TextParseUtil.translateVariables((String)
val, stack); //
                }
                stack.setValue(entry.getKey().toString(), val); //
duplicated, it should be only once
            }

In my opinion it should be changed to this, removed duplicated entry

            for (Iterator iterator = parameters.entrySet().iterator();
                 iterator.hasNext();) {
                Map.Entry entry = (Map.Entry) iterator.next();

// it's duplicated
//stack.setValue(entry.getKey().toString(), entry.getValue());

                Object val = entry.getValue();
                if (parse && val instanceof String) {
                    val = TextParseUtil.translateVariables((String)
val, stack); //
                }
                stack.setValue(entry.getKey().toString(), val); //
duplicated, it should be only once
            }


and one thing, you should put parse param on interceptor, not on action

            <interceptor-ref name="staticParams">
                <param name="parse">true</param>
            </interceptor-ref>
            <param name="cardNo">${params.myid}</param>



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: Newbie Q: How to set session object parameters in struts.xml

Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 6/24/08, John Smith <de...@gmail.com> wrote:
> Does the syntax ${something} retrieve the object from the session?

No.

The previous answer, implementing SessionAware, was one of the correct answers.

Dave


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


Re: Newbie Q: How to set session object parameters in struts.xml

Posted by John Smith <de...@gmail.com>.
I have implemented sessionAware and the process works for a static
string but it doesn't work for objects :(

So I have the following in my struts.xml:

        <action name="blah"
            class="blahAction">
            <param name="parse">true</param>
            <param name="test">hello</param>
            <param name="something">${something}</param>
            <result>out.jsp</result>
        </action>

the "test" param works fine which is a simple string but the the other
param "something" does not work.

Does the syntax ${something} retrieve the object from the session?




On Tue, Jun 24, 2008 at 11:10 AM, Lukasz Lenart
<lu...@googlemail.com> wrote:
> Hi,
>
>> Is it possible to set session objects inside and action and access the
>> session object in another action without explicitly retrieving the
>> session object?
>
> Implement SessionAware interface with yours actions and put and get
> value from that map ;-)
>
>
> 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: Newbie Q: How to set session object parameters in struts.xml

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

> Is it possible to set session objects inside and action and access the
> session object in another action without explicitly retrieving the
> session object?

Implement SessionAware interface with yours actions and put and get
value from that map ;-)


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