Hello,
I'm building an editable parent / child
JSP page. I have a single object derived from ActionForm backing the JSP page. The form object contains an ArrayList of JavaBean objects - one for each child row. The ArrayList is populated from a database on initial display of the page. I'm using the <logic:iterate> tag etc. to display the child info. No problems so far.
The page allows the user to add new child objects to the parent object (e.g. these will wind up being new rows in a database). What I'm trying to do is simulate a single save (ACID transaction) for the whole page. I want to do trips to the server whenever the user adds a new child row. I'd like to add a child object to the form's ArrayList to keep the population logic in the JSP page simple. I *don't* want to save the new object out to the database right away.
The problem is the ActionForm doesn't retain any "object" state. On the post,
Struts calls getChildObject(int index) on the ActionForm. The backing ArrayList is null at this point. In the past, I've just repopulated the ArrayList by going back to the database "just in time." In this case, not so nice since some of the objects aren't represented in the database.
I'm sure many people have run into this as it would be the same issue for the classic "shopping cart" example.
Options I can think of are:
- storing intermediate, temporary rows in the database
- using the Session
- some Struts feature to serialize object state and send it on the request
None of these are particularly appealing.
Any help would be greatly appreciated.
Thanks,
Mike.