I am using a MVC framework which is a bit like struts.
So, say I have a “Edit Store” link in my application this is how the url would look like:
http://localhost:9080/test?action=editStore&storeNum=10
Now, action determines my Action (analogous to Struts Action) to be run. The corresponding action here is: EditStoreAction. Clicking this would open a pop up with different attributes of a store for edit.
My question here is:
How do I write my actions? Do I write two actions in this context?
- EditStoreAction which will render
edit.jsp - StoreSaveAction which
will invoked when user presses
accept on the rendered response of
edit.jsp.
OR Do I just write one action? EditStoreAction and submit form to the same action, I would know that the user has pressed the accept button for changes on submission. So, I would execute a different flow in the Action, which would save updates to database and redirect to a diff page.
What is the best pratice here? Create as many actions as possible coz it keeps the code modular? OR just write one action to handle everthing in a jsp?
I know this question sounds a bit trivial, however, sometimes you just want to get everything right. Hence, the question. Appreciate your help.
The idea is, similar to Spring MVC, to map your actions to the methods of a specific class, say it controller.
So, in your case, these two actions will be mapped on two different methods of the same class. You can call the class
StoreFormControllerand two methods,editStore()andsaveStore().Better still if you make two controllers for each entity. May be one for all GET requests and another is for POST requests. So, in your case there would be two controllers
StoreControllerfor all other requests andStoreFormControllerfor all form submissions, namely post requests. Now, your first action being GET will go toeditStore()method ofStoreController, whereas the second being POST request will go tosaveStore()method ofStoreFormController. You can define as many methods as needed in any of these two classes based on the request type.You can easily see, where I am coming from, if you know Spring MVC API.