struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kam Lung Leung" <kle...@wlwa.com>
Subject RE: how to retrieve property values from previous forms/jsp pages
Date Mon, 03 Nov 2003 21:20:13 GMT
Thank again David,

> HotelBean hotel = (HotelBean) request.getSession().getAttribute("hotel");

Is the string "hotel" the name of the form that was declared in the
struts-config.xml? 

 <form-beans>
    <!-- CreateUserAccountForm form bean -->
    <form-bean  name="hotel" type="com.wlwa.Forms.HotelSecondForm"/>
  </form-beans>

Many Thanks,
Kam Lung Leung

On Mon, 3 Nov 2003 15:58:24 -0500, "David Friedman" wrote:

> 
> Kam,
> 
> You can force a bean into the session scope by setting 'scope="session"' in
> the action mapping <action.../> (or <action>...</action>).  To retrieve
it,
> you can do something like this:
> 
> HotelBean hotel = (HotelBean) request.getSession().getAttribute("hotel");
> CarBean auto = (CarBean) request.getSession().getAttribute("car");
> 
> Then, when you're done with them in the final page, you can remove them (or
> let  them expire with the session, but I recommend removing beans when they
> are no longer needed)
> 
> request.getSession().removeAttribute("car");
> request.getSession().removeAttribute("hotel");
> 
> More details can be found on the Java ServLet Spec available on the net such
> as on the Tomcat 4.1 site:
> 
> http://jakarta.apache.org/tomcat/tomcat-4.1-doc/servletapi/javax/servlet/htt
> p/HttpSession.html
> 
> You can also set the cookie to last longer (see the interval set/get
> functions) so sessions last longer than 30 minutes (Tomcat a default, I
> think).
> 
> Regards,
> David
> 
> -----Original Message-----
> From: Kam Lung Leung [mailto:kleung@wlwa.com]
> Sent: Monday, November 03, 2003 3:44 PM
> To: struts-user@jakarta.apache.org
> Subject: RE: how to retrieve property values from previous forms/jsp
> pages
> 
> 
> Thank David,
> 
> The second option may not work for me because the secondPage.jsp will be
> further
> extends to hotel.secondPage.jsp, car.secondPage.jsp and so on. The purpose
> of the
> finalPage.jsp is to echo all values that were inputted from either the hotel
> group(firstpage.jsp and the hotel.secondPage.jsp), or the card group
> (firstpage.jsp and the car.secondPage.jsp). Then the user have the option to
> either submitted or goes back to the firstPage.jsp.  Thus I should not
> combine
> the hotel.secondPageForm.java and car.secondPageForm.java into the
> firstPageForm.java (that becomes combinedPagesForm.java). This will make the
> combinedPagesForm.java too difficult to maintains in the future. The third
> option
> looks more fit into my situation?  How do i put the action's bean in the
> session
> scope? Do you mean setting the scope to session in the action mapping. I
> thought
> the scope setting was for the form bean. Can you give a simple code example?
> How do I retrieve the property values of firstForms in my execute method of
> the
> hotel.secondAction.java?
> 
>    public ActionForward execute(ActionMapping mapping,
>                                   ActionForm form,
>                                   HttpServletRequest request,
>                                   HttpServletResponse response)
>                 throws Exception {
> 
>       hotel.secondForm inputForm = (hotel.secondForm) form;
>       // retrieve all property values
> 
>                 ....
> 
>       //Now what to do to get the firstForm from here??
>    } //end execute
> 
> May be I need to use the request.setAttribute to setup a DAO object in the
> firstAction.java and retrieve the DAO object from within the execute method
> of
> the hotel.secondAction.java by using the request.getAttribute method? Can
> this be
> done?
> 
> Thank you in advance,
> Kam Lung Leung
> 
> 
> On Mon, 3 Nov 2003 14:23:27 -0500, "David Friedman" wrote:
> 
> >
> > Kam,
> >
> > One approach is to use hidden variables to ensure all fields are in every
> > page.
> >
> > Another approach is to have each action use the same form in "session"
> scope
> > so all fields are retained between POSTs (just remember to
> > getSession().removeAttribute(NAME) when you're done with it to free up
> > memory.
> >
> > A third approach is to put each action's bean in the "session" scope
> similar
> > to the previous paragraph.  Again, remember to remove the session beans
> when
> > you're finished with them to keep your memory usage down.
> >
> > I prefer the 2nd approach: one bean in session scoped shared by multiple
> > actions.
> >
> > Regards,
> > David
> >
> > -----Original Message-----
> > From: Kam Lung Leung [mailto:kleung@wlwa.com]
> > Sent: Monday, November 03, 2003 2:18 PM
> > To: struts-user@jakarta.apache.org
> > Subject: how to retrieve property values from previous forms/jsp pages
> >
> >
> > Hi,
> >
> > I need to retrieve property values from previous pages that were inputted
> by
> > the
> > user. For example;
> > I have the following pages, actions and forms.
> > firstPage.jsp firstAction.java firstForm.java
> > secondPage.jsp secondAction.java secondForm.java
> > finalPage.jsp finalAction.java finalForm.java
> >
> > In the finalAction class I need to retrieve property values that were
> filled
> > in
> > from the firstPage.jsp and the secondPage.jsp. Beside setting the scope of
> > each
> > form to session in the action mapping what else do I need to do so that I
> > may
> > retrieve those values?
> >
> > Any suggestion?
> > Thank you in advance.
> > Kam Lung Leung
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org

Kam Lung Leung
System Architect
Wireless Web Access Inc.
(303) 627-9684

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


Mime
View raw message