• Post Reply Bookmark Topic Watch Topic
  • New Topic

Advise if I am in correct direction

 
Dan Parsons
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a search tool where someone has three fields (Name, City and JobTitle) to search in an Oracle database.

I am going to use MVC pattern because I want to learn and master MVC eventually using MVC frameworks such as Struts and JSFs. Please advise if I am correct in how I am going to do this project:

The Search page will be done with JSP.
The action page coming from the JSP Search page will go to a Controller Servlet. The Controller Servlet will pull up a record that will be shown in JSP with JavaBeans to grab the field values of the record. That page with the JavaBean values will have an Update and Delete Button. If the user hits either button it will go back to the Controller Servlet which will grab a helper class (The helper class method will be called in the Controller servlet) that has database Update or Delete SQL statement and execute the query. Also the database opening and closing connection will be in one helper class that is called in the Controller Servlet.

A session reponse will then be forwarded to a JSP with a message confirming what took place.
[ June 14, 2007: Message edited by: Dan Parsons ]
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If i were you, i would have used Struts.

As a matter of fact, your specifications can be done in both Struts and JSF, you can even do it with core Servlets and JSP.

Best of luck ...
 
Dan Parsons
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have Struts or JSF due to restrictions where I am at and it could be a year before I get those frameworks. Please advise if I am in the right direction or not in my MVC?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65518
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Controller Servlet will pull up a record that will be shown in JSP with JavaBeans to grab the field values of the record.


It sounds as though you are forgetting all about the M and doing the work of the model in the C.

P.S. I would endorse neither of Struts or JSF.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ditto for not using a framework; especially if you're doing this to learn MVC.

What like to do to separate the M from the C and V is write a Plain Old Java Object (POJO) that can perform the business (database) operation.
In this class I make sure not to import anything from the javax.servlet packages. If done correctly, you'll have a business object that can be called from any front end written in Java (Command Line, Swing, Servlet, JUnit, Axis webservice, etc...)

Once this object is built and I can verify that it's working by calling its main method from the command line, then, I start writing the front end to it.

The front end components--Servlets in this case--should never need to import any classes from the java.sql package. All they have to know is that they can instanciate these classes, and call their methods, and voila, they get back results that can be read from the JSPs.

The only thing database related information that needs to be passed from the web tier to your business objects is the JNDI connection string (if you're using JDBC) and the web tier doesn't even need to know that that is JNDI related. It just knows that it needs to pass them some configuration string.
 
Dan Parsons
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, all the info you all gave me is great.

I will now work on more Model classes.

For example in below Model class partial example, I am using JavaBeans to validate a business rule (rule is saying all country entries have to be Alameda) and wondering if this is in the right direction for enforcing abusiness rule in a Model class?

[ June 17, 2007: Message edited by: Dan Parsons ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!