Rick:
  I think the problem is in how you are initializing your objects.  In particular the 
problem is where you call the setCarList() method.  Both Persons are getting a 
reference to the same list.  In other words you have only one car list in memory.  So, 
when you modify it, you are modifying the car list for both persons.

Make sense?

Aside: Try not to initialize your bean in the reset() method.  It gets called each 
time the form is submitted before Struts sets the values the user provided.  Can you 
somehow, move that logic to the Action class?

Sri

-----Original Message-----
From: Rick Reumann [mailto:maillist@;reumann.net] 
Sent: Monday, November 04, 2002 2:09 PM
To: Struts Users Mailing List
Cc: Sri Sankaran
Subject: Re[2]: Nested Tags situation any light would be appreciated




On Monday, November 4, 2002, 1:43:35 PM, Sri wrote:

SS> That brings us to what happens when the page is submitted. You
SS> *should* (as a test) be able to set up an action that does nothing
SS> and just forwards back to the same location.

    What is odd is something goes wrong during the process of being
    submitted to the action. The action does as you mention..just
    forward back to the same location:

   public ActionForward getResults(ActionMapping mapping,
                                ActionForm form, 
                                HttpServletRequest request, 
                                HttpServletResponse response) 
                                throws IOException, ServletException {

        String forward = "continue";
        NestingForm f = (NestingForm)form;
        request.setAttribute(mapping.getAttribute(), f);
        return mapping.findForward(forward);
    }    

    The odd thing is if you cycle through the ArrayList of people in
    this action and print out what you get you find all indexes
    populated with the whatever Person object is in index 0 of people.

     I tested the above with this:
       ArrayList people = f.getPeople();
        for ( int i = 0; i< people.size(); i++ ) {
            Person person = (Person)people.get( i );
            Logging.info("\nName: "+person.getName() );
            ArrayList carList = person.getCarList();
            for ( int n = 0; n < carList.size(); n++ ) {
                CarBean car = (CarBean)carList.get( n );
                Logging.info("  Car: "+car.getCarName()+" - "+car.isCarSelected() );
            }
        }

    So the problem is somehow from whatever is going on 'behind the
    scenes' from when submit is called, then reset, then to the
    action. I've tried just about everything in the reset method of
    the form. Currently for debugging and I'm going through in the
    reset and repopulating everything just like I do in the first
    action that sets up the page. I figured this would be ok since I
    thought when I submit and after reset is called then everything in
    the jsp form overwrites whatever the reset did?

    In the reset method I'm doing this:

       ArrayList cars = new ArrayList();

        CarBean car = new CarBean();
        car.setCarName("Mustang");
        car.setCarSelected(false);
        cars.add(car);

        car = new CarBean();
        car.setCarName("Mercedes");
        car.setCarSelected(false);
        cars.add(car);

        car = new CarBean();
        car.setCarName("Porsche");
        car.setCarSelected(false);
        cars.add(car);

        //normally get form business layer
        people = new ArrayList();

        Person person = new Person();
        person.setName("Juan");
        person.setCarList(cars);
        people.add(person);

        person = new Person();
        person.setName("Rick");
        person.setCarList(cars);
        people.add(person);

        person = new Person();
        person.setName("Jeff");
        person.setCarList(cars);
        people.add(person);
 
        setPeople(people);


SS> Does your form-bean do anything in the reset and/or validate
SS> methods?

    No validation is being done. Reset is as above.

    Thanks so much for helping debug this.

    Rick
    
<ORIGINAL MESSAGE BELOW:>

SS> -----Original Message-----
SS> From: Rick Reumann [mailto:maillist@;reumann.net]
SS> Sent: Monday, November 04, 2002 10:20 AM
SS> To: Struts List
SS> Subject: Nested Tags situation any light would be appreciated


SS> Sorry to repeat this question... possibly some fresh Monday blood 
SS> could help...

SS> I'm stumped here what I'm screwing up and would appreciate any help. 
SS> I'm playing around using nested tags and for a simple example in my 
SS> first action that brings me to the jsp everything gets prepopulated 
SS> and the display is fine:

SS> Ex output:
SS> =================================
SS> John
SS> Enter Favorite Cars:
SS> Mustang        Porsche       BMW

SS> Bill
SS> Enter Favorite Cars:
SS> Corvette       Mercedes      Viper

SS> Fred
SS> Enter Favorite Cars:
SS> A              B             C
SS> ==================================

SS> The problem is when you change the name of any of the cars, after 
SS> the form submits and returns you to this page, it populates all the 
SS> rows with whatever the first row has in it (In this case if you did 
SS> nothing and hit submit all 3 rows would look like John's row). I'm 
SS> sure it's something simple I'm screwing up and would appreciate any 
SS> help. Here's the basics of the jsp nested tag page:

SS> <nested:form  action="myAction">

SS>        <nested:iterate property="people" >

SS>        <nested:write property="name"/><brR>
    
SS>         Enter in Cars:<br>

SS>         <nested:iterate property="carList">

SS>             <nested:text property="carName"/>
    
SS>         </nested:iterate>

SS>         <br><br><br>

SS>     </nested:iterate>

SS> <nested:hidden property="dispatch" value="getResults"/> <br><br> 
SS> <html:submit styleClass="field" value="GET RESULTS"/>

SS> </nested:form>

SS> //reminder:

SS> Form Bean
SS>      ArrayList people

SS>      people is populated with Person beans

SS>             Each Person bean has the field
SS>                  String name;
SS>                  ArrayList carList

SS>                            carList is a list of CarBeans
SS>                                    CarBean just has String carName

                                   
SS> people = ArrayList in form bean of Person beans
SS> name = String in Person Bean
SS> carList = ArrayList of CarBean beans
SS> carName = String field in CarBean



-- 

Rick
mailto:maillist@;reumann.net


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

Reply via email to