Is the addAddress() method of your PersonForm simply a cover for the ArrayList's add 
method?  In other words, is it simply doing addresses.add(object-to-add)?

Can you test the size of the list in the getter to see if data is indeed being 
clobbered?

Sri

-----Original Message-----
From: Jonathan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 27, 2003 7:20 PM
To: 'Struts Users Mailing List'
Subject: RE: Session Problems


The form bean is simply a standard action form, when its created It simply does the 
following in the constructor

public PersonForm() {
                        
        addresses = new ArrayList(20);                  
}

To get the addresses and iterate through them I simply have:

/**
 * Get Addresses
 */
public Object[] getAddresses() {
        return (this.addresses.toArray()); 
}

When the second form is submitted the following method is called In the 
AddAddressAction via the lookup dispatch action:

public ActionForward addAddress(ActionMapping mapping, 
                                          ActionForm form, 
                                          HttpServletRequest request, 
                                          HttpServletResponse response) throws 
Exception {
                                        
                                                                
                
                //Check that the token is valid, if it is then reset it
                if(isTokenValid(request)) {
                        
                        System.out.println("Token is valid, resetting
the request");
                        resetToken(request);
                }                       
                else {
                        System.out.println("Token is invalid");
                }
        
                                        
                //Get the action form
                PersonForm personForm = (PersonForm)form;               
                                        
                int addressId = (personForm.getNumberOfAddresses() + 1);
                
                System.out.println("New id is " + generatedId);
                
                //Create the question option from the buffered values
                Address address = new Address (generatedId, new String("address"));

        

                
                //Add the question option to the action form
                personForm.addAddress(address);                  
                
                
                //Save a token for this request to prevent automatic refreshing
                //from submitting the request again
                System.out.println("Saving the token");
                saveToken(request);

         //Now the address has been added return to the add person page

        return (mapping.findForward("addPerson"));
        }       

The address is added but the next time I try to add an address to old one Is 
overwritten..

Jon.



-----Original Message-----
From: Sri Sankaran [mailto:[EMAIL PROTECTED] 
Sent: 27 February 2003 18:54
To: Struts Users Mailing List
Subject: RE: Session Problems

Can you summarize the form bean you are using for the first page?  What are its 
properties?  How is the Collection maintained?  How is the bean being created?

Sri

-----Original Message-----
From: JONATHAN PHILIP HOLLOWAY [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 27, 2003 12:01 PM
To: Struts Users Mailing List
Subject: Session Problems


Hi,

I'm curerntly having problems with sessions in Struts.

I have two JSP's both of which point to the same action.

In my first JSP I have a number of basic properties and a list of addresses as shown 
below:

*Name:  Bill Blah
*Age:  23

* Addresses (list)
23 Glamorgan Street  |  ER34 5RT  | Edit | Delete
13 Glamorgan Street  |  ER34 6TT  | Edit | Delete

The addresses are simply displayed using a logic:iterate tag.  

I also supply a link on this page to add an address in a seperate page, this JSP 
allows a user to add an address to the list in the first page. 
When the page is submitted it is simply added to in the actionform.

Once I've entered the new address using this second page I'm returned tot he first 
page where the new address is shown in the list of addresses. the problem I have is 
that when I add a second address it removes the first address and only the second 
address is shown here as:

* Addresses (list)
13 Glamorgan Street  |  ER34 6TT  | Edit | Delete

instead of 

* Addresses (list)
23 Glamorgan Street  |  ER34 5RT  | Edit | Delete
13 Glamorgan Street  |  ER34 6TT  | Edit | Delete

I'm assuming this is a problem with the session, could somebody please explain to me 
why this happening.  I have set the scope to session for both JSP pages and both JSP 
pages use the same action form so why is this happening?

Many thanks,
Jon.


*---------------------------------------------*
 Jonathan Holloway,               
 Dept. Of Computer Science,       
 Aberystwyth University, 
 Ceredigion,                      
 West Wales,                      
 SY23 3DV.                        
                                  
 07968 902140                     
 http://users.aber.ac.uk/jph8     
*---------------------------------------------*

---------------------------------------------------------------------
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