I'm using Struts 1.3.10 and tiles working on a set of Actions all using the same ActionForm as follows:
EnterOrderForm -- extends ValidatorActionForm and contains a nested bean for 1-n rows of information boxes (one box per row)
EnterOrderAction --> simply puts together an order page that populates the EnterOrderForm when submitted. Works fine. Has a submit button to call next action (GetPricingAction). Uses EnterOrder.jsp There is no validation here
GetPricingAction --> performs calculations (calls business layer), stuffs calculated results into EnterOrderForm . Declarative validation (validation.XML) is turned on and input page is last action. Works fine. NO data entry here... this has only calculation and display capability. Has a submit button to call next action (PlaceOrderAction) -- uses GetPricing.jsp
PlaceOrderAction --> does NOT work fine. Uses PlaceOrder.jsp for displaying data. There is no validation of previous form data, since no data was entered in the prior step. For some reason, the EnterOrderForm presented here is a newly initialized form-- NOT the one from the prior steps. I've confirmed this via debugging (looked at request object where last Action was supposed to place it) and dumped all scope fields on JSP page. Page presents fine, and no errors in the console. The EnterOrderForm is just null.
Form is scoped as "request" for all steps. Does anyone know why I can't get the form data from when it was entered into the PlaceOrderAction? that is, what might cause the EnterOrderForm to go to null?? Do I need all fields present on the form?
The code / config-- for your reference:
My Action configs:
Hoping someone sees something I don't.
Joined: Dec 11, 2010
I should've been clearer... what I was wondering is:
Do I **HAVE** to put things in SESSION scope? since I have a bean that can take any number of rows of box information, i can't predict how many boxes I'll have. I could write a JSP to loop through the collection, place the hidden fields in the page, then submit the lot to the next Action. This seems cumbersome.
Lastly, do I have to clear the object out of the Session or does Struts handle this? Are there any problems I should expect with double form submits? I was thinking of writing a base class to check session IDs and remove the offendor-- has anyone done this?
The form needs to get its values from somewhere. If you use session scope then they will come from the session. If you use request scope then they will be submitted from the user's browser. So if you are using request scope, then the values need to be on the screen, probably as you mentioned, as hidden fields. I always use request scope (for no better reason than thats how the app I work on was set up when I started) and one of the draw backs is that you need to make hidden fields for any data that you want to come back to the server that isn't displayed in some other kind of form field. Using the iterate and hidden tags in your JSP to hide the values shouldn't be too hard, but if you prefer session scope, that should work as well.
Joined: Dec 11, 2010
Thanks for the quick reply.
It seems that avoiding session is good for memory, but I don't have large objects / lot of data-- so this should be fine. Saves me from coding a number of JSPs.