The collection is loaded into the form when I first get the page and works fine. Then if I select any of the books, the action is to be repeated and certain particulars of the book are to be populated on the same page. The problem is: if I keep the scope as session everything is fine, but if the scope is request, the form data is lost even before the reset is called and the control is not going into the action handler. It's giving ArrayIndexOutofBoundsException:0 index 0. I think it's because books field(collection) in the form has 0 size as if the form itself is being initiated with 'new'. All other values in the form are also defaults.
Can anybody please advise how could this happen? using struts1.1.
I read over the link. I would agree that the preferred method (Manually call validate and use Request Scope) is pretty good and maybe a reason for me to switch over to DispatchAction or at least update my code so that the "display" and "save" actions are implement in a single java file.
I use a different technique. I drive different functionality of my "display" action by configuring multiple action mappings that use the same action class but pass in different parameter values. The parameter is "Refresh" then the action know that it just needs to retrieve the dynamic data for the page (such as lists). My save action would be configured to use the "refresh" action for the input parameter.
Thanks for the replies. Jason & Brent I have gone throught the content in the link, but my problem is not a validaion failure. Even before calling validate(), reset() gets called and by this time itself the form is losing all the data. Hope you unserstood Soumya, when the form is losing data, how can we access the collection. It's case of the form being in session and everything works fine. Except that the servers are loaded with huge session data and so I am trying to replace with request scope.
Maybe it would help if you described the mechanism that you have in place in more detail. It sounds like your page has a list of books, and when the user selects one of the books then properties of the book (maybe cost, author and publisher) are shown on the page. When a book is selected, do you submit the page? If so, how do you detect that the user selected a book instead of clicking the "save" button?
Here is what I do for this...When a book is selected a script sets the value of the "refreshControl" property. My base action class for handling saves detects that this value is set and then forwards to the input property instead of saving the record. The input property is defined to call the "refresh" action. The refresh action takes care of loading dynamic values and in this case it might query the database to get the properties associated with the selected book. I am not sure if this makes any sense.
Since the submission and display are all on the same request, all the values that the user has entered into the form are retained along with any hidden fields. You just need to make sure that any values that are not submitted with the form are populated during the refresh processing.
Hi Brent, I was temporarily moved to a different problem. Coming back, I get the page with a list of books(each book is a BookDTO with all particulars). The list is shown on the page with a check box and book name. When the user selects a paricular book and submits this request struts is giving a problem of ArrayIndexOutOfBoundsException. The selection is maintained in the checkbox. The form is losing the list of books(ArrayList) and so we are getting that exception. The other string parameters in the form are in tact. Thanks Sai
From the little that I can tell about your page, I would agree with the solution posted by Soumya. If you are not editing the properties of a book in place then I don't see a need to used indexed properties. Index properties would be used if you had a list of books on your page and the end user could edit the price of each book and then save all the updated prices at once.
Soumya/Brent, I too think this might work. But I have to see how I can maintain the association between the selected ones and the corresponding BookDTOs. I have to go with checkboxes as per our screens. Thanks for the lead.
What a stench! Central nervous system shutting down. Save yourself tiny ad!