tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <wbar...@wilshire.com>
Subject Re: Java Bean Scope questions (a lengthy one)
Date Thu, 09 Jan 2003 06:55:53 GMT

"Denise Mangano" <DeniseM@complusdata.com> wrote in message
news:5D83C44941AFD4118B6F0002B302984F43863C@EXCHANGE_SERVER...
> Bill,
>
> I'm not sure what you mean.  The transaction Bean gets instantiated when I
> call CCSubmit.jsp.  That is the first time it is "mentioned" and CCSubmit
is
> only called once from Verify.jsp.  Is what you are saying effectively the
> same as:

Taking a wild guess, I'm thinking that you want 'formBean' to have
scope="session", and 'transaction' to have scope="request".  This way,
'formBean' stays around between pages, but 'transaction' only stays around
for the one request that it is needed.

What I was pointing out is that any <jsp:setProperty ...> that is nested
within a <jsp:useBean ...> ... </jsp:useBean> acts as a first-time
initialization (sort of like a "constructor").  If the bean has already been
constructed, then it won't be called again.  To set the property every time,
you need to place the <jsp:setProperty ...> tag outside of the <jsp:useBean
...> tag.

>
> <jsp:useBean id="transaction" class = "com.complusdata.beans.Transaction"
> scope="session" >

This code will only be executed if there is *no* "transaction" in the
session (and the JSP page needs to create a new one.  If you have previously
called CCSubmit.jsp (or if you had any other page that used "transaction")
at any point with this session, it will be skipped.

>   <jsp:setProperty name="transaction" property="email"
> value="<%=formHandler.getEmail()%>"/>
>    ....
> </jsp:useBean>
>
> Thanks.
>
> Denise Mangano
> Help Desk Analyst
> Complus Data Innovations, Inc.
>
>
> -----Original Message-----
> From: Bill Barker [mailto:wbarker@wilshire.com]
> Sent: Wednesday, January 08, 2003 1:42 AM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Java Bean Scope questions (a lengthy one)
>
>
>
> "Denise Mangano" <DeniseM@complusdata.com> wrote in message
> news:5D83C44941AFD4118B6F0002B302984F438636@EXCHANGE_SERVER...
> > Wow someone read all of that!! ;)
> >
> > For Question #1:  I should have mentioned this before... I tried to
> > use session scope at one point (don't recall the exact reason but I
> > thought of it as an attempt to resolve a different problem).  When I
> > set the scope to session, it caused problems with my form validation.
> > Currently if the
> form
> > is not validated, the user is brought back to Retry.jsp and error
> > messages appear next to the offending input field.  When I used
> > session scope, Retry.jsp would be reloaded, but the error messages
> > would not be displayed... Any thoughts on that?  I am going to go back
> > and attempt this again now that everything is working as it should up
> > to Verify.jsp and see if I stand corrected...
>
> You need:
> <jsp:useBean id="transaction" class = "com.complusdata.beans.Transaction"
> scope="session" />
>   <jsp:setProperty name="transaction" property="email"
> value="<%=formHandler.getEmail()%>"/>
> ....
>
>
> Note the final '/>' on jsp:useBean.  The way that you had it originally,
the
> properties will only be set if the JSP page needs to create a new instance
> of "transaction".  If it finds one in the session already, the setters are
> skipped.
>
>
>
> >
> > For Question #2 - that's exactly what I needed to know!!
> >
> > For Question #3 - hopefully I can get the session scope to work, but
> > then how would I program that button?  Would I just put
> > onClick="Retry.jsp" ?
> >
> > Tim, thank you so much for taking the time!!
> > Denise :)
> >
> > -----Original Message-----
> > From: Tim Moore [mailto:tmoore@blackboard.com]
> > Sent: Tuesday, January 07, 2003 9:24 PM
> > To: Tomcat Users List
> > Subject: RE: Java Bean Scope questions (a lengthy one)
> >
> >
> > > -----Original Message-----
> > > From: Denise Mangano [mailto:DeniseM@complusdata.com]
> > > Sent: Tuesday, January 07, 2003 9:19 PM
> > > To: 'Tomcat Users List'
> > > Subject: Java Bean Scope questions (a lengthy one)
> > >
> > >
> > > Question #1: Why does CCSubmit.jsp not have access to formBean
> > > properties. I am thinking this is because technically by submitting
> > > a form with an action of "CCSubmit.jsp" control isn't being
> > > forwarded to CCSubmit.jsp so the instance of formBean isn't
> > > forwarded.  The scope of formBean is request. Is that the correct
> > > scope to use?  **I need to have access to formBean properties from
> > > the moment it is instantiated to the moment the application
> > > has completed, but it has to be unique to each user of the
> > > webapp.**   How
> > > could I accomplish this?
> >
> > That's exactly what session scope is for. :-) Request scope means that
> > the bean is gone at the end of the request (that is, when Verify.jsp
> > finishes rendering).  If you put it in session scope you'll be set.
> >
> > > Question #2: Is it possible to use two beans within a single jsp
> > > page?  I would imagine that it is, and if so I believe once I gain
> > > access to formBean properties, my transaction properties will no
> > > longer be null. (I included some code below... is this legal?)
> >
> > Absolutely!  As long as they have different id attributes, you can use
> > as many beans as you like.
> >
> > > Question #3:  I include a button to give the option to go back and
> > > make changes.  If the user should desire to go back and make
> > > changes, control should be forwarded to Retry.jsp on button click.
> > > I need to program this button in a way so that when Retry.jsp is
> > > recalled it will still have access to formBean properties.How do I
> > > program this? My last attempt using <jsp:forward> cause Retry.jsp to
> > > load automatically when Verify.jsp was loaded (sorry again Noel ;)
> > > ).
> >
> > As long as the bean is in session scope, you'll be able to access it
> > from any page the user accesses.
> > --
> > Tim Moore / Blackboard Inc. / Software Engineer
> > 1899 L Street, NW / 5th Floor / Washington, DC 20036
> > Phone 202-463-4860 ext. 258 / Fax 202-463-4863
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:tomcat-user-help@jakarta.apache.org>
>
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>




--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message