Data reposting when forwarding to Action

2003-07-10 Thread John M. Corro
I'm currently running into an issue w/ data reposting after I've forwarded to
another Action.

In my ActionForm, say I have an ArrayList of ApplicationUser objects.  In the
associated JSP page, I list the data for each ApplicationUser object in a HTML
table (one row for one ApplicationUser).

The flow I'm trying to setup is as follows:
1. User types in some URL that maps to a setup type action.  In this setup Action
the ApplicationUser objects are retrieved from persistence and loaded into the
ActionForm.  The request is then forward to the appropriate JSP page.

2. The user clicks a checkbox on one of the rows to denote that they'd like
that specific ApplicationUser deleted and then hits submit.  

3. The HTML form data is posted to a URL that maps to an Action that processes
the data appropriately (in this case deleting the ApplicationUser).  The request
is then forwarded to the same URL as in step 1 (so that the HTML page they just
came from is redisplayed w/ the updated data).


If I understand correctly, these are the sequence of events at a technical level:


1. User posts data for saving (ie hits 'Submit' button)

2. Struts invokes reset() on ActionForm.  
** NOTE: I needed to implement a hack here - normally in the reset() method
you return all attributes to non-valued states.  So in this case the ArrayList
that would hold all the ApplicationUser objects is cleared out.  However, if
I do clear them out, I run into an IndexOutOFBoundsException because Struts
will try to populate the form values into an empty ArrayList of ApplicationUser
objects.  As a result, in the reset method I have to repopulate the ApplicationUser
objects back into the Form.  I've been on several Struts projects and have never
found a good way of dealing w/ this (populating form list data in two spots:
setup Action and reset method).  If anyone has any good ideas, I'd LOVE to hear
them!

3. Struts populates data from HTML post into ActionForm

4. Struts forwards to the Action that does the processing.

5. The Action deletes the appropriate user from persistence and forwards to
a setup type Action.

6. Struts invokes reset() on ActionForm
** NOTE: Now at this point one user was deleted so the size of the ArrayList
will be smaller than when we started.

7. Struts attempts to populate data from the original HTML post into the ActionForm.
 When Struts tries to access the last element, it throws an IndexOutOfBoundsException
(because the number of ApplicationUser objects is now reduced by one).

I'm not 100% certain that step #7 is taking place, but it's a reasonable explanation
for why I get the IndexOutOfBoundsException.

So my question to the group is
- Can someone confirm that step #7 is occuring
- Recommend any alternative approachs to sidestep the problem or prevent the
reset() method from getting invoked before the setup Action.
* Extra points for anyone who can recommend a good way of dealing w/ the hack
noted in step #2 :)


John M. Corro
Cornerstone Consulting

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Data reposting when forwarding to Action

2003-07-10 Thread Sandeep Takhar
Yes step #7 is occuring.

One of the reasons for not chaining actions together.

sandeep
--- John M. Corro [EMAIL PROTECTED]
wrote:
 I'm currently running into an issue w/ data
 reposting after I've forwarded to
 another Action.
 
 In my ActionForm, say I have an ArrayList of
 ApplicationUser objects.  In the
 associated JSP page, I list the data for each
 ApplicationUser object in a HTML
 table (one row for one ApplicationUser).
 
 The flow I'm trying to setup is as follows:
 1. User types in some URL that maps to a setup type
 action.  In this setup Action
 the ApplicationUser objects are retrieved from
 persistence and loaded into the
 ActionForm.  The request is then forward to the
 appropriate JSP page.
 
 2. The user clicks a checkbox on one of the rows to
 denote that they'd like
 that specific ApplicationUser deleted and then hits
 submit.  
 
 3. The HTML form data is posted to a URL that maps
 to an Action that processes
 the data appropriately (in this case deleting the
 ApplicationUser).  The request
 is then forwarded to the same URL as in step 1 (so
 that the HTML page they just
 came from is redisplayed w/ the updated data).
 
 
 If I understand correctly, these are the sequence of
 events at a technical level:
 
 
 1. User posts data for saving (ie hits 'Submit'
 button)
 
 2. Struts invokes reset() on ActionForm.  
 ** NOTE: I needed to implement a hack here -
 normally in the reset() method
 you return all attributes to non-valued states.  So
 in this case the ArrayList
 that would hold all the ApplicationUser objects is
 cleared out.  However, if
 I do clear them out, I run into an
 IndexOutOFBoundsException because Struts
 will try to populate the form values into an empty
 ArrayList of ApplicationUser
 objects.  As a result, in the reset method I have to
 repopulate the ApplicationUser
 objects back into the Form.  I've been on several
 Struts projects and have never
 found a good way of dealing w/ this (populating form
 list data in two spots:
 setup Action and reset method).  If anyone has any
 good ideas, I'd LOVE to hear
 them!
 
 3. Struts populates data from HTML post into
 ActionForm
 
 4. Struts forwards to the Action that does the
 processing.
 
 5. The Action deletes the appropriate user from
 persistence and forwards to
 a setup type Action.
 
 6. Struts invokes reset() on ActionForm
 ** NOTE: Now at this point one user was deleted so
 the size of the ArrayList
 will be smaller than when we started.
 
 7. Struts attempts to populate data from the
 original HTML post into the ActionForm.
  When Struts tries to access the last element, it
 throws an IndexOutOfBoundsException
 (because the number of ApplicationUser objects is
 now reduced by one).
 
 I'm not 100% certain that step #7 is taking place,
 but it's a reasonable explanation
 for why I get the IndexOutOfBoundsException.
 
 So my question to the group is
 - Can someone confirm that step #7 is occuring
 - Recommend any alternative approachs to sidestep
 the problem or prevent the
 reset() method from getting invoked before the setup
 Action.
 * Extra points for anyone who can recommend a good
 way of dealing w/ the hack
 noted in step #2 :)
 
 
 John M. Corro
 Cornerstone Consulting
 

-
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 


__
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]