struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jim Barrows" <jbarr...@sssc.com>
Subject RE: Data not being populated from database on form jsp
Date Tue, 03 Aug 2004 19:50:39 GMT


> -----Original Message-----
> From: Shilpa Nalgonda [mailto:snalgonda@mypublisher.com]
> Sent: Tuesday, August 03, 2004 12:35 PM
> To: Struts Users Mailing List
> Subject: RE: Data not being populated from database on form jsp
> 
> 
> Thi soptions looks better to me,
> "Alternatively when you get the shipping information from the datbase
> initially, copy it to an ActionForm, and use that for display 
> everywhere.
> THis would mean setting the name and validation fields in the 
> strutsconfig
> for each action that uses the form.  Display only should have 
> validation
> off."
> 
> But how can i copy the database info to Action Form is there 
> any struts API
> to do that...and also how can i make the validation off .. i 
> am a starter in
> Struts, can u give the code snippets for this..

>From http://struts.apache.org/userGuide/building_controller.html section 4.8.1
<action
            path="/logon"
            type="org.apache.struts.webapp.example.LogonAction"
            name="logonForm"
            scope="request"
            input="/logon.jsp"
            unknown="false"
            validate="true" />  <------------Change this to false

To do the copy, I highly recommend http://jakarta.apache.org/commons/beanutils/
BeanUtils.copyProperties(into, from);  will do most conversions... if you have special conversions
then you can register your conversion classes and it will use your custom conversion....


> 
> Thanks.
> 
> 
> -----Original Message-----
> From: Jim Barrows [mailto:jbarrows@sssc.com]
> Sent: Tuesday, August 03, 2004 3:30 PM
> To: Struts Users Mailing List
> Subject: RE: Data not being populated from database on form jsp
> 
> 
> 
> 
> > -----Original Message-----
> > From: Shilpa Nalgonda [mailto:snalgonda@mypublisher.com]
> > Sent: Tuesday, August 03, 2004 12:22 PM
> > To: Struts Users Mailing List
> > Subject: RE: Data not being populated from database on form jsp
> >
> >
> > I retrieve some shipping information from database and this
> > information is
> > displayed in OrderSummary.jsp .
> > There is a link on orderSummary.jsp file to go to Shipping
> > page and edit it.
> > I am not able to populate the shipping form when the edit
> > button is clicked
> > on OrderSummary Page.
> >
> > This is what i am doing --
> > 1) checkCustomer.jsp -- user enters email address in a text
> > box.  when the
> > submit button is clicked here,
> > checkCustomerAction class is called and  retrieves the 
> entire shipping
> > information from database and stores the shipping object in session.
> >
> > 2) OrderSummary.jsp -- displays the shipping information from
> > the session.
> > There is an additional link to Edit Shipping form.  i have
> > used html:link to
> > go to shipping.jsp like below
> > "<html:link page="/editShipping.do">
> >    <bean:message key="edit"/>
> >  </html:link> "
> 
> The class for editShipping.do should probably copy the 
> shipping information
> to a form, and then forward to the shipping.jsp page.  If the 
> user modifies
> the shipping information, then validate and copy back to the 
> session object.
> 
> Alternatively when you get the shipping information from the datbase
> initially, copy it to an ActionForm, and use that for display 
> everywhere.
> THis would mean setting the name and validation fields in the 
> strutsconfig
> for each action that uses the form.  Display only should have 
> validation
> off.
> 
> >
> >
> > 3) shipping.jsp -- when the user click on edit button from
> > OrderSummary,
> > shipping.jsp is populated all blank.fields.
> >
> > My question is how and where should i populate the
> > shippingForm bean. i have
> > a class called ShippingForm.java which has all the getters
> > and setters for
> > shipping.  Should the html link take any parameters?  or should i do
> > something in editShippingAction class Please help....
> >
> > -----Original Message-----
> > From: Jim Barrows [mailto:jbarrows@sssc.com]
> > Sent: Monday, August 02, 2004 7:50 PM
> > To: Struts Users Mailing List
> > Subject: RE: Data not being populated on edit in my jsp file...
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: Shilpa Nalgonda [mailto:snalgonda@mypublisher.com]
> > > Sent: Monday, August 02, 2004 4:08 PM
> > > To: Struts Users Mailing List
> > > Subject: RE: Data not being populated on edit in my jsp file...
> > >
> > >
> > > Let me make it clear..
> > >
> > > I have a jsp file called OrderSummary.jsp which has a link
> > > called "EDIT",
> > > which should take me to EditShipping.jsp file.
> > > User first enters his billing and shipping information in a
> > > session and
> > > finally comes to  a order summary page from there he can go
> > > back to the
> > > EditShipping.jsp page by clicking on the link .
> > > So when i click on the link , the application should take 
> me back to
> > > shipping page with all the fields populated.
> > > But my shipping page fields are all empty.  I have stored
> > the shipping
> > > information in session .  But in EditShipping.jsp i do not
> > > use any of the
> > > session attributes to display the values.   Go over my edit
> > > shipping.jsp
> > > file and let me know i fi am missing something.
> >
> > Doesn't look like it.  You have the form beans as session.
> > Whenever you go
> > back to the page, you should see it populate... my only
> > thought is what is
> > going on inside the action?  Last time I ran into this
> > problem I stupidly
> > was clearing out the form.
> >
> > You might try dumping the form to system.out on each jsp and
> > action in the
> > process, and see if it's still there and populated.
> >
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Jim Barrows [mailto:jbarrows@sssc.com]
> > > Sent: Monday, August 02, 2004 6:58 PM
> > > To: Struts Users Mailing List
> > > Subject: RE: Data not being populated on edit in my jsp file...
> > >
> > >
> > >
> > >
> > > > -----Original Message-----
> > > > From: Shilpa Nalgonda [mailto:snalgonda@mypublisher.com]
> > > > Sent: Monday, August 02, 2004 2:29 PM
> > > > To: Struts Users Mailing List
> > > > Subject: Data not being populated on edit in my jsp file...
> > > >
> > > >
> > > > I have a jsp fle which has a html link to EditShipping.jsp file.
> > > > All the attributes in EditShipping.jsp should be populated,
> > > > but its not
> > > > happening.
> > > > CAn anyone help me out...
> > >
> > > Let me see if I understand:
> > > You have a jsp file (call it first.jsp) and have <html:link
> > > href="/EditShipping.jsp"/> or <a href="/EditShipping.jsp"/>
> > > or something the
> > > renders an <a href to the EditShipping page.
> > >
> > > If that's it.. then why would you expect any kind of
> > > communication between
> > > pages with a link?  You would either have to add in the
> > > parameters, or use a
> > > <html:form tag to post the data in the first page.
> > >
> > >
> > > >
> > > > below is my EditShipping.jsp file...Struts config file..and
> > > > OrderSummary.jsp  on which the hyperlink is displayed.
> > >
> > > EditShipping.jsp---
> > > > =====================================================
> > > > <html:form action="/editShipping">
> > > > 	<div>
> > > > 		<bean:message key="prompt.FirstName"/>
> > > >  		<html:text property="firstName" size="50"/><br>
> > > >
> > > > 		<bean:message key="prompt.LastName"/>
> > > >                 <html:text property="lastName" size="50"/><br>
> > > >
> > > > 		<bean:message key="prompt.StreetAddress"/>
> > > > 		<html:text property="address1" size="50"/><br>
> > > >
> > > > 		<bean:message key="prompt.Address2"/>
> > > > 		<html:text property="address2" size="50"/><br>
> > > >
> > > > 		<bean:message key="prompt.City"/>
> > > > 		<html:text property="city" size="50"/><br>
> > > >
> > > > 		<bean:message key="prompt.State"/>
> > > > 		<html:select property="state">
> > > >   		<html:option value="NY">New York</html:option>
> > > > 		<html:option value="NH">New 
> Hampshire</html:option>
> > > >  		<html:option value="NJ">New Jersey</html:option>
> > > > 	        </html:select>
> > > > 	        <br>
> > > > 		<bean:message key="prompt.Country"/>
> > > > 		<html:select property="country">
> > > >  		<html:option value="US">UNITED STATES OF
> > > > AMERICA</html:option>
> > > > 	        </html:select>
> > > > 		<br>
> > > >
> > > > 		<bean:message key="prompt.Zip"/>
> > > > 		<html:text property="zip" size="50"/><br>
> > > >
> > > > 		<bean:message key="prompt.PhoneNumber"/>
> > > > 	 	<html:text property="phone" size="50"/><br>
> > > >         </div>
> > > > ==============================================================
> > > > Sruts Config.xml
> > > > =======================================
> > > >   <action
> > > >          path="/checkCustomer"
> > > >         type="com.ecommerce.action.CheckCustomerAction"
> > > >         name="CheckCustomerForm"
> > > >         scope="session"
> > > >         input="/CheckCustomer.jsp">
> > > >     <forward name="new" path="/EditShipping.jsp" />
> > > >     <forward name="returning" path="/OrderSummary.jsp" />
> > > >      </action>
> > > >
> > > >    <action
> > > >          path="/editShipping"
> > > >         type="com.ecommerce.action.EditShippingAction"
> > > >         name="ShippingForm"
> > > >         scope="session"
> > > >         input="/EditShipping.jsp">
> > > >     <forward name="success" path="/ShippingMethod.jsp" />
> > > >     <forward name="failure" path="/EditShipping.jsp" />
> > > >    </action>
> > > > =====================================================
> > > > OrderSummary.jsp ---
> > > >
> > > > <html:link page="/editShipping.do">
> > > >   <bean:message key="edit"/>
> > > > </html:link>
> > > > ==========================================================
> > > >
> > > > -----Original Message-----
> > > > From: Research labs [mailto:research_labs@yahoo.co.uk]
> > > > Sent: Monday, August 02, 2004 5:17 PM
> > > > To: Struts Users Mailing List
> > > > Subject: Re: DaTASOURCE CREATION AT USER LOGIN TIME...Newbie
> > > >
> > > >
> > > > Craig,
> > > >
> > > > Thanks a lot.  All points taken.  In the light of what
> > > > you and Jim have said, I will re examine my plan of
> > > > action
> > > >
> > > > I found out about you in one of my books "Struts in
> > > > Action" by Ted Husted et al.  If I may, I would like
> > > > to keep this first email from you as some sort of
> > > > autograph.
> > > >
> > > > Ola.
> > > >
> > > >
> > > >  --- Craig McClanahan <craigmcc@gmail.com> wrote:
> > > > > On Mon, 2 Aug 2004 21:23:05 +0100 (BST), Research
> > > > > labs
> > > > > <research_labs@yahoo.co.uk> wrote:
> > > > > > Jim,
> > > > > >
> > > > > > Thanks for your response.
> > > > > > I want each user to login to the database(MySQL),
> > > > > via
> > > > > > a JSP.  Once logged in, I want them to use their
> > > > > > database username (specified at log in time) for
> > > > > > communicating with the database throught their
> > > > > > session.  To put it another way, if 4 users are
> > > > > > currently logged in (via a JSP etc.), When I query
> > > > > the
> > > > > > data dictionary of the database, I want their
> > > > > names to
> > > > > > come up.  At any point in time, I want to be able
> > > > > to
> > > > > > find out, who is logged in, this is why I do not
> > > > > want
> > > > > > everyone to log in with the same username and
> > > > > password
> > > > > > e.g. ola/ola-hardcoded in the Struts config's
> > > > > > data-source.
> > > > > >
> > > > >
> > > > > Do you care about finding out who is logged in to
> > > > > your *application*,
> > > > > or who is logged in to the *database*?  Those can
> > > > > easily be made
> > > > > separate questions, and in most cases should be
> > > > > separate.
> > > > >
> > > > > > I do not mind using any datasource so long as I
> > > > > can
> > > > > > achieve my objective.
> > > > > >
> > > > >
> > > > > The <data-source> element in struts-config.xml, like
> > > > > using most JNDI
> > > > > provided data sources, will not address your need.
> > > > > That is because
> > > > > they create application wide pools for shared
> > > > > connections.
> > > > >
> > > > > Doing what you want to do, however, will also be
> > > > > giving up on the key
> > > > > advantage of using a data source in the first place
> > > > > -- sharing a small
> > > > > number of database connections between multiple
> > > > > users.  By definition,
> > > > > if you are using per-user logins to the database,
> > > > > such connections
> > > > > cannot be shared.  That can be problematic for the
> > > > > scalability of your
> > > > > app, because it will require more database resources
> > > > > to be allocated
> > > > > than would otherwse be necessary.  Plus, you'll
> > > > > likely run into limits
> > > > > on how many individual database connections can be
> > > > > opened before you'd
> > > > > ever run out of capacity in your web server to
> > > > > support simultaneous
> > > > > users.
> > > > >
> > > > > If all you care is logins to an application, here's
> > > > > a couple of easy
> > > > > ways to do that while still sharing database
> > > > > connections:
> > > > >
> > > > > * At login time, write into some table someplace a
> > > > > row for the logged in user,
> > > > >   and make sure you clean it up when they log out or
> > > > > when the session
> > > > >   expires.  To see who is logged in, run database
> > > > > queries against
> > > > >   this table.
> > > > >
> > > > > * Store some in-memory data structure (perhaps as an
> > > > > application scope
> > > > >   attribute), and have the login/logout logic add
> > > > > and remove entries from
> > > > >   this data structure.  To see who is logged in, set
> > > > > up a Struts action or
> > > > >   something that will go through the data structure
> > > > > and list all the logged
> > > > >   on users.
> > > > >
> > > > > If you still really want per-user database logins,
> > > > > then give up on the
> > > > > idea of using any sort of data source -- it won't
> > > > > buy you anything.
> > > > > Instead, create a standalone JDBC connection at
> > > > > login time, and store
> > > > > it in session scope somewhere.  But I would suggest
> > > > > you consider the
> > > > > disadvantages of such an approach before using it.
> > > > >
> > > > > > Thanks.
> > > > > > Ola.
> > > > > >
> > > > >
> > > > > Craig
> > > > >
> > > > >
> > > >
> > >
> > 
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > > user-unsubscribe@struts.apache.org
> > > > > For additional commands, e-mail:
> > > > > user-help@struts.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > ___________________________________________________________ALL
> > > > -NEW Yahoo!
> > > > Messenger - all new features - even more fun!
> > > http://uk.messenger.yahoo.com
> > >
> > >
> > 
> ---------------------------------------------------------------------
> > > 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
> > >
> > >
> > >
> > 
> ---------------------------------------------------------------------
> > > 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
> > >
> > >
> >
> > 
> ---------------------------------------------------------------------
> > 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
> >
> >
> 
> ---------------------------------------------------------------------
> 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
> 
> 

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


Mime
View raw message