I want to show some data from database in a form. Then this data is changed by the user and will be saved again to the database. I want to minimize the round trips to the database. So I want one action to show data in form and the same action take the data from form and save it to the database. Is there anyway to do it.
Fawad Ali wrote: I want to minimize the round trips to the database.
I don't know how you are going to save trips to the database. Any way you shake it, you have 2: one to get the data to display, one to update the data.
As for using the same Action class for both both purposes, it depends on which version of Struts you are using.
Struts 1.x: One option is to extend Action with a class that looks for a request parameter "step" which can have the values "prepare" and "commit". This class invokes different methods depending on which value is set. If the value is "prepare", run the logic for displaying the data. If the value is "commit", run the logic for updating the data.
Struts 2.x: One can configure the display and save URL's in struts.xml to invoke the display or commit method on the action.
Thanks buddy. I am using Struts 2. Sorry I didnt mention that earlier. I have done it in the same way you told me. I have declared tow actions pointing to the same action class. In a view part, I instantiate an object of class Event event and show it on page. In submit part, it throws Null pointer exception. Here is the code
I think that on each call to the class a new instance is made, so in view part I am getting event from db but in save the event is null. So any suggestions on this?