This message is rather long, just a warning. . .

Hello all,

I would like to start this message by thanking those who have contributed to
the model 2 discussion that I have been following.  After reading (and
re-reading) over the threads, I thought it would be a good time to discuss
my design strategies and learn how to move towards an "action class" design.
I spent the weekend thinking about this design concept and had a few basic
questions that I need answered before I can continue.

Let me start by explaining how I am currently implementing a model 2 like
behavior.  I would also like to mention that it is difficult (in my
position) to learn alternative architectural strategies without some input
from you guys, so feel free to tell me other areas where I could improve my
design.

Basically my applications follow a semi model 2 approach that has been
discussed at length by Craig, Kevin and others.  The application usually
begins with a jsp which instantiates any beans I will need and places them
in the session.  The user fills out any necessary information and submits
the page which gets sent to a control servlet (for lack of a better name).
This servlet uses the extra path info, for example <FORM
ACTION="/servlet/blahServlet/extra/path/info" .. >, to determine which
method (within the servlet) should be executed.  Within each method, I check
each data entry, set appropriate errors and error messages if necessary (I
use an ArrayList as I display a number of error messages typically), and
call the setXXX() method of the bean.  If an error occured, I place the
ArrayList (containing appropriate error messages) in the session and forward
to the appropriate page.  I do this so that user reloads maintain error
messages (and I am taking care to cleanup this ArrayList of course).  If
everything was ok, I perform some business logic (still within the servlet)
and forward to an appropriate confirmation page.

Now, following the discussion regarding model 2 design strategies, I have
seen the power of using specialized action classes and path information
instead of placing all the methods within the controller servlet (plus this
tends to make the servlet incredibly large).  I am looking to begin
implementing this sort of strategy, but must first get some basics out of
the way.

Craig gave some pseudocode for an action class that had the perform method:

        public interface Action {
          public void perform(HttpServlet servlet, HttpServletRequest
request, HttpServletResponse response)
                throws IOException, ServletException;
        } // ends interface Action

(thanks Craig)

Now my questions are, what is the advantage is passing an HttpServlet
object?  I understand HttpServletRequest and HttpServletResponse, but why
HttpServlet?  Also, assuming you answer this, HOW do you pass this inside
the servlet (sounds trivial but I have never tried any such thing)?

There was mention of 2 HashTables (or HashMaps) used in the controller
Servlet.  If I am understanding correctly, the first maps the requestURI to
the appropriate action class, and the second is used to store an instance of
the appropriate action class?  So, in theory, you would grab the requestURI
and look it up in the first HashTable.  Once the appropriate class is
determined, you look for an instance of that class in the second HashTable?
You would then call the perform method on that class (if it exists) or
instantiate the class and call the perform method?  I have not worked a lot
with dynamic class loading so a little help here would be greatly
appreciated.  Maybe a little pseudocode to get me over the hump?

I had some concern about something craig mentioned in the brevity of his
action classes (being 50 - 100 line mostly performing setXXX()).  In my
servlet, I am doing all my setXXX() error checking where it seems you are
performing this in the bean (or maybe I am just not writing as concise
code?).  If this is the case, how do you know when the data is inappropriate
for the field (ie, characters were found in a social security number?).  In
my case, I do this checking in the servlet.  If an error has occured, I set
the bean to an appropriate value (sometimes to null, and sometimes to the
input value so that it can be easily modified by the user).  Otherwise I
just set the bean property.  Could you go into a little more detail on this
please?  As I mentioned earlier, it is hard to learn alternative design
strategies when there are little to no examples to learn from =).

One more thing (as if this email isnt long enough). . . I read mention of
using yet a public HashTable (or was it a method)? to determine which page
the action class should forward to instead of hardcoding the value within
the action class.  Is this really all that advantageous?  I like the idea of
having logic names mapped to a specific file name, but otherwise, this seems
to be overhead in projects that dont span hundreds of pages (or dont have
the possibility of spanning that large).  I assume, in this strategy, the
action class would lookup the logical name prior to forwarding to the .jsp
refered to in the controller servlet?

I hope this all makes sense.

Thanks to everyone for helping me in understanding some of these basic
issues I am having.  I look forward to your replies :).

Thanks

Jeff

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to