View Full Version : design simple application question
shoa
Apr 29th, 2006, 02:10 AM
Hello all
I need to develop a simple application that allows users to login (from homepage page) into a page that allows him to add, delete and update books in a store.
the book object that is updated or added into system needs to have the userId who updates or add.
In my thingking, I will create a FormController for the login page. If user logins correctly, an user object of this user will be created and a session will be created and store this user object. The FormController of the next page will use the function FormBackingObject to obtain this user object. Then userId of this user object will be add into added book (if add new book) in onSubmit function....
Could you please tell me it is correct or there is better way to do this
Thank you
shoa
Colin Yates
Apr 29th, 2006, 04:38 AM
If your application really is as simple as this, then yes, your proposal should be fine.
I would also consider writing a user filter that checks to see if the user is logged in, and if not, sends them to the login filter.
Example:
/user/login.htm - user login details (UserLoginController)
/app/books/list.htm - list of all books (ListBooksController:SimpleFormController)
/app/books/add.htm - add a book (AddBookController:SimpleFormController)
/app/books/delete.htm - delete a book (DeleteBookController:Controller)
/app/books/update.htm - update a book (EditBookController:SimpleFormController)
In web.xml I would map the login filter to /app/*.htm. In the login filter I would check if the user is in the session; if not redirect to /user/login.htm.
You might consider using a single MultiActionController for the CRUD operations of a book, but I prefer to use seperate controllers.
I did scope these suggestions to "a really simple application" :) If it starts getting any more complex then I would maybe look at ACEGI security, AbstractWizardFormController for simple sequential steps through a usecase or Spring Web Flow for more complex usecases.
A few parts of Spring/utility classes/ideas you might find useful:
- in deleted/controller you will want to override formBackingObject to retrieve the command object, which will be the book:
public Object formBackingObject(....) {
String bookId = RequestUtils.getRequiredStringParameter(BOOK_PARAM );
Book book = bookManager.loadBook(bookId);
return book;
}
- in your UserLoginController map, keep the user under a well known name (maybe "user") in the session; that way all your JSPs will automatically have access to it.
- you will need to decide the scope of a book in the *FormController; either request or session. I personally do not like *anything* in the session because it makes clustering servers more difficult, so I always load the objects for every request. Others don't mind and keep it in the session. Keeping anything in the session increases the memory footprint per user on the server but reduces database access. Keeping nothing in the server makes your servers completely stateless (from a user perspective) and scales extremely well, but does increase database access. Still in my experience, the DB is bored out of it's mind waiting for stuff to do :)
HTH.
shoa
Apr 29th, 2006, 05:21 AM
thank you very much for your help
No, my application is not simple as the post 1. I am only one in this project for adding/delete books and I need to have an user object. Another person will do the security/upload image...... I need a guide to do my part :)
Thanks
Colin Yates
Apr 29th, 2006, 06:37 AM
thank you very much for your help
No, my application is not simple as the post 1. I am only one in this project for adding/delete books and I need to have an user object. Another person will do the security/upload image...... I need a guide to do my part :)
Thanks
Well just keep asking questions :) We are all here to help and learn.
shahzad992
May 2nd, 2006, 01:50 AM
/app/books/list.htm - list of all books (ListBooksController:SimpleFormController).
Hi yatesco!
i think it(ListBooksController) must me controller not the SimpleFormController. As it is the list of books available nothing else.and u can also use it for delete and opening the book record for update purposes.
Am i right?
Regards,
shahzad
Colin Yates
May 2nd, 2006, 03:57 AM
Hi yatesco!
i think it(ListBooksController) must me controller not the SimpleFormController. As it is the list of books available nothing else.and u can also use it for delete and opening the book record for update purposes.
If you are having a controller simply to populate the list of books, then yes, it shouldn't be the SimpleFormController (my mistake :)). If you want a single controller to return the list of books, delete a book etc. then you will want to use MultiActionController (although I prefer seperate controllers ;)).
shoa
May 2nd, 2006, 04:51 AM
I am using MultiActionController for the book form list. It work fine
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.