Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web-State Pattern

 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Akin Kaldiroglu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic