Iterate the action? Oh I thought the second time you ran through it was
after the user had submitted the form, at least that was the impression I
had got from the comments in the code:
<snip>
else if (formBean.isBlnUpdateAction())  // user clicks 'update' in
"first.jsp",  Run through this Action class the 2nd time
</snip>

No idea then.

Unless you mean by 'iterate' future invokations of the same action from new
requests?
(Thats not what I understand by the term iterate...)

In this case what you need to remember is that the lifetime of a request is
only the processing of that request. Ie - request (GET or POST) comes in
from the browser, the container creates an HttpServletRequest object that
encapsulates the information in the request, processes the request (sends it
the the ActionServlet where it is processed by your action and perhaps
forwards to further resources (most notably the jsp) to be handled). The
processing of the request having been completed, response writing etc... ,
that HttpServletRequest object goes out of scope. Future (and indeed
simultaneous) requests from browsers will get their own HttpServletRequest
objects.

The request attributes set is tied to a single request object and when that
object goes out of scope obviously you cant get at its attributes anymore
(unless you have some other reference to them of course) - and this is why
you often hear people say things like "put the object into request
scope...".

If you need to share and keep track of stuff across multiple requests (and
threads) then you may use the session or servlet context objects for this.


-----Original Message-----
From: Au-Yeung, Stella H [mailto:[EMAIL PROTECTED]
Sent: Thursday, 17 July 2003 12:24
To: 'Struts Users Mailing List'
Subject: RE: Request object Null Pointer


I thought once I store an attribute into the 'request' object, it will be
available no matter how many times I iterate through the same Action class?
If it doesn't do that, then how do I store data into the request object so I
can use it again later in the same Action class or even in a different
Action class.  Thx.

-----Original Message-----
From: Andrew Hill [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 17, 2003 12:06 AM
To: Struts Users Mailing List
Subject: RE: Request object Null Pointer


Well of course its null.

The second time through you arent calling
request.setAttribute("vehList",vehList) before calling
prepareListForUpdate()


-----Original Message-----
From: Au-Yeung, Stella H [mailto:[EMAIL PROTECTED]
Sent: Thursday, 17 July 2003 10:52
To: '[EMAIL PROTECTED]'
Subject: Request object Null Pointer


Hi:
I am getting a NULL pointer with the request object:  Please see code below.
I got a NULL pointer trying to access "vehList' in the request object inside
the method "prepareListForUpdate".  But I didn't get  a NULL pointer
accessing "vehList" inside the method "setScheduleList".
So it looks like the 1st time it ran through the Action class, the request
object is ther.   But the 2nd time it ran through the Action class, either
the request object is null or "vehList'  is no longer in the request object.
===============================
Portion of Action class:
ArrayList vehList = new ArrayList();
 ==> initialize and set values for vehList here <====

if (formBean.isSearchAction())  // user clicks 'search' on form.   Run
through this Action class the 1st time
 {
        request.setAttribute("vehList",vehList);
        this.setScheduleList(request);          // invoke another method
        <===  eventually "first.jsp" with an 'Update" button is displayed

}
else if (formBean.isBlnUpdateAction())  // user clicks 'update' in
"first.jsp",  Run through this Action class the 2nd time
 {
         this.prepareListForUpdate(request);    // invoke another method
}

=============================
 Portion of method "setScheduleList":

setScheduleList(javax.servlet.http.HttpServletRequest request)
{
        // display vehList.size() AND IT PRINTED OUT OK
        ArrayList l = (ArrayList) request.getAttribute("vehList");
        EtLog.debug(this,"in setScheduleList, vehList,size()="+l.size());
}
==================================
Portion of method "prepareListForUpdate":

prepareListForUpdate(javax.servlet.http.HttpServletRequest request)
{
        // display vehList.size()  AND IT GAVE ME A NULL POINTER EXCEPTION
        ArrayList l = (ArrayList) request.getAttribute("vehList");
        EtLog.debug(this,"in prepareListForUpdate,
vehList,size()="+l.size());
}
====================================
Any help will be appreciated,
Newbie




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to