I've been asked to look into the Web-State Pattern for some JSP / servlet work I'm about to start ... is this the same as the MVC pattern? from what I understand both make use of JSPs (view) JavaBeans & Servlets (model & controller). Has anyone done any development using this pattern? How does it essentially work?
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
It may be related to the "State" pattern in GoF (always worth a re-read for any patter question). In the State pattern, the state of a process is represented by an instance of a class which implements an interface (or extends a particular base class). To change state, simply replace the state object with another object. The code using the state object neither knows or cares which state it is in. For a web-specific use you might have a single JSP in which a named bean represents the state. Either in the JSP or in one or more associated servlets, you could make sure that the correct bean is in the session ready for the JSP each tim eit is called. Does this make sense?
MVC-State Pattern is actually is the combination of MVC and State patterns. Main idea is based on a servlet that acts like a controller to get the requests from the web clients and delegate it to the model. So far it is pure MVC. The effect of State pattern comes when your model have different states and all these states are represented with different JSP. So the Context in the State pattern of GOF corresponds to the servlet itself. It sends the requests to State interface and depending upon the state which your state-dependent object is the servlet redirect the response to a different JSP, which is specificaly designed for that state. In this scenario, of course your servlet should know about which state is active. Akin Kaldiroglu
Angela Poynton
Ranch Hand
Joined: Mar 02, 2000
Posts: 3143
posted
0
Ok I finally got some documentation on this from someone here ... essentially it's a combination of state and MVC patterns. The JSP being the view, Javabeans handle the model and we have controller Servlets there is also a state class which handles the state so the controller Servlet doesn't need to know the state .. it receives an HTTP request and invokes processRequest() on the instance of the State calss in the Session profile. i think that's it ... the document is quite confusing I'll need to read through it again!
Alok Pota
Ranch Hand
Joined: Mar 07, 2001
Posts: 185
posted
0
Angela, Can I you email the doc to me or give me the link where I can read it. Thanks Alok (apota@dmotorworks.com)
Angela Poynton
Ranch Hand
Joined: Mar 02, 2000
Posts: 3143
posted
0
I'm afraid it contains a lot of stuff confidential to the company. If I get time one day I might make a version of my own!