wood burning stoves 2.0*
The moose likes Spring and the fly likes Spring MVC design help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring MVC design help" Watch "Spring MVC design help" New topic
Author

Spring MVC design help

Ravi Shankar Mukkavilli
Greenhorn

Joined: Feb 10, 2009
Posts: 12
Hello All,

I'm new to Spring MVC and trying out a simple project.It will contain a simple adding, viewing, updating and deleting user work flows. It will have login page and once authenticated the user will be taken to a welcome screen which will have links to add, view, update and delete users. Clicking on any of the links will take to individual pages where the user can do the specific tasks. What I'm doing here is, I'm using a MultiActionController to group together all requests related to User work flow. As the user cannot directly access the addUser.jsp file which is inside the WEB-INF folder, so the request from "Add User" link will handled by the addUser method in the UserController which will redirect the user to the "Add User" page, and the user can then fill in the details and save the new user. Now here is where I'm getting confused. Where should I put the save process of the new user, should I put that in new method inside UserController, or use the same "addUser" method. What is the best way to handle this kind of scenario. Can you provide me with some sample code. Thanks

I hope I was able to clear my question.

SCJP 1.4
SCWCD 1.4
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I would make separate methods for each action. For example, one called "show", which would show the form, and one called "save", used to save to information.


[My Blog]
All roads lead to JavaRanch
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

If you started learning Struts, the developing a simple CRUD application wouldn't be a problem.

Better you avoid MultiActionController and stickwith Annotations to map the methods with corresponding to the path.


Never try to be a hard-worker. Be a smart-worker.
My Blog
Ravi Shankar Mukkavilli
Greenhorn

Joined: Feb 10, 2009
Posts: 12
Thanks guys.

@Rajkumar: I don't have much idea about Spring annotations, but I'm interested in trying it. Can you direct me to a simple example. I did wrote a SimpleFormController (without annotations) in which I configured the Command name ,class, the form view and success view in the constructor something like this



Can you provide me with a sample code/tutorial for the about code in annotations. Thanks for your help.

Ravi
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You'll find some examples in the official reference.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445


Although christopher provide the link, i'll post a simple equivalent code for yours.

 
 
subject: Spring MVC design help