You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Janice <ja...@shaw.ca> on 2004/02/24 21:00:57 UTC

need help converting from session to request scope

Hi Gang,

I've been doing things badly... putting everything in session scope.  The
good news is that everything works beautifully :)  But now that I've got
100+ actions I've decided to go put stuff into request scope.  The bad news
is that everything grinds to a halt.

Here's an example of where I've added the scope to an action mapping:
<--- snip --->
    <action    path="/yearlyAllocation"
               input=".yearlyAllocationForm"
               parameter="action"
               type="ca.bc.gov.srm.bart.actions.YearlyAllocationActions"
               scope="request"
               name="yearlyAllocationForm"
               validate="false">
      <forward name="form"      path=".yearlyAllocationForm" />
      <forward name="list"      path=".yearlyAllocationList" />
      <forward name="gotolist"  path="/yearlyAllocation.do?action=showList"
/>
    </action>
</--- snip --->
Previously I'd left the scope line out.

So my now jsp page can't find my form goodies on the page.  It falls apart
here:
<--- snip --->
      <html:select property="yearCode">
        <html:optionsCollection property="years" label="yearFull"
value="yearCode" />
      </html:select>
</--- snip --->
with a NullPointerException.  But it did make it past here:
<--- snip --->
<html:form action="/yearlyAllocation?action=submitForm"
      name="yearlyAllocationForm"
      type="org.apache.struts.validator.DynaValidatorForm"
      focus="yearCode">
</--- snip --->
which I guess I'm surprised at.

I'd love to put up all kinds of code, but I'm using DispatchActions, tiles,
DynaValidatorForms, etc, so I'm not really sure where to start cutting and
pasting.  If anyone has any requests for more info, I'd be happy to oblige.

Oh, this one looks important: in my method where I set up the form before
passing it to the .jsp, I set up my form all pretty with lots of Strings and
ArrayLists and then I do one of these:
<--- snip --->
      if ( "request".equals(mapping.getScope()) ) {
        request.setAttribute(mapping.getAttribute(), form);
      } else {
        HttpSession session = request.getSession();
        session.setAttribute(mapping.getAttribute(), form);
      }
</--- snip --->
which I thought was designed to handle this.

So, to make a long story short, what else do I need to do to switch from
putting all my form beans in session scope to putting them in request scope?
Do I need to tell the .jsp page to look somewhere else or something?

Thanks very much in advance,
Janice


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


Re: need help converting from session to request scope

Posted by Hubert Rabago <ja...@yahoo.com>.
I'm just here to give my opinion on your "this one looks important" item.
Let's say you have ActionA to setup your form with lots of Strings and
ArrayLists as you said, and ActionB to which the form you're setting up
eventually gets submitted to.

In your ActionA, you're calling "request".equals(mapping.getScope()).  The
mapping object you have at this point is for ActionA, but the form's scope is
defined in ActionB, so mapping.getScope() doesn't give you the scope of the
form you're after.  That's why it's not working as you expected.

 - Hubert

--- Janice <ja...@shaw.ca> wrote:
> Oh, this one looks important: in my method where I set up the form before
> passing it to the .jsp, I set up my form all pretty with lots of Strings
> and
> ArrayLists and then I do one of these:
> <--- snip --->
>       if ( "request".equals(mapping.getScope()) ) {
>         request.setAttribute(mapping.getAttribute(), form);
>       } else {
>         HttpSession session = request.getSession();
>         session.setAttribute(mapping.getAttribute(), form);
>       }
> </--- snip --->
> which I thought was designed to handle this.
> 
> Thanks very much in advance,
> Janice
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

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


Re: need help converting from session to request scope

Posted by Hubert Rabago <ja...@yahoo.com>.
Okay, I'll add a bit more since nobody else is.
>From what I understand, some of your scenarios are like this.  You have
ActionA to set up your Strings and ArrayLists etc to display FormA, and FormA
gets submitted to ActionB.  So, your config for these look something like:

<action path="/showForm" type="ActionA">
    <forward name="showForm" path=".formATile">
</action>

<action path="/submitForm" 
    type="ActionB"
    name="formA"
    input=".formATile"/>

To use request scope, you can either:
1) Leave your Strings/ArrayLists in session scope
2) Put them in application scope
3) Put them in request scope, then change your ActionB mapping to use ActionA
as input.  You'll need to make sure you don't reset FormA's values in ActionA
when it's for a redisplay.

I'm pretty sure this has been discussed in the list before, and that I've
typed the text for #3 before.
Anyway, choose one solution above (it's up to you and your reqts/situation)
and try it for one form.  If it works, try it for another form.

Hubert

--- Janice <ja...@shaw.ca> wrote:
> Hi Gang,
> 
> I've been doing things badly... putting everything in session scope.  The
> good news is that everything works beautifully :)  But now that I've got
> 100+ actions I've decided to go put stuff into request scope.  The bad news
> is that everything grinds to a halt.
> 
> Here's an example of where I've added the scope to an action mapping:
> <--- snip --->
>     <action    path="/yearlyAllocation"
>                input=".yearlyAllocationForm"
>                parameter="action"
>                type="ca.bc.gov.srm.bart.actions.YearlyAllocationActions"
>                scope="request"
>                name="yearlyAllocationForm"
>                validate="false">
>       <forward name="form"      path=".yearlyAllocationForm" />
>       <forward name="list"      path=".yearlyAllocationList" />
>       <forward name="gotolist"  path="/yearlyAllocation.do?action=showList"
> />
>     </action>
> </--- snip --->
> Previously I'd left the scope line out.
> 
> So my now jsp page can't find my form goodies on the page.  It falls apart
> here:
> <--- snip --->
>       <html:select property="yearCode">
>         <html:optionsCollection property="years" label="yearFull"
> value="yearCode" />
>       </html:select>
> </--- snip --->
> with a NullPointerException.  But it did make it past here:
> <--- snip --->
> <html:form action="/yearlyAllocation?action=submitForm"
>       name="yearlyAllocationForm"
>       type="org.apache.struts.validator.DynaValidatorForm"
>       focus="yearCode">
> </--- snip --->
> which I guess I'm surprised at.
> 
> I'd love to put up all kinds of code, but I'm using DispatchActions, tiles,
> DynaValidatorForms, etc, so I'm not really sure where to start cutting and
> pasting.  If anyone has any requests for more info, I'd be happy to oblige.
> 
> Oh, this one looks important: in my method where I set up the form before
> passing it to the .jsp, I set up my form all pretty with lots of Strings
> and
> ArrayLists and then I do one of these:
> <--- snip --->
>       if ( "request".equals(mapping.getScope()) ) {
>         request.setAttribute(mapping.getAttribute(), form);
>       } else {
>         HttpSession session = request.getSession();
>         session.setAttribute(mapping.getAttribute(), form);
>       }
> </--- snip --->
> which I thought was designed to handle this.
> 
> So, to make a long story short, what else do I need to do to switch from
> putting all my form beans in session scope to putting them in request
> scope?
> Do I need to tell the .jsp page to look somewhere else or something?
> 
> Thanks very much in advance,
> Janice
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools

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