You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/11/04 20:09:19 UTC
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 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 could help...
SS> I'm stumped here what I'm screwing up and would appreciate any help. I'm playing around using nested tags and for a simple example in my first action that brings me to the jsp everything gets
SS> prepopulated 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 the form submits and returns you to this page, it populates all the rows with whatever the first row has in it (In this case if
SS> you did nothing and hit submit all 3 rows would look like John's row). I'm sure it's something simple I'm screwing up and would appreciate any 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> <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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>