[prev in list] [next in list] [prev in thread] [next in thread] 

List:       velocity-user
Subject:    Simple design
From:       Barbara Baughman <baughman () utdallas ! edu>
Date:       2004-05-25 23:41:32
Message-ID: Pine.GSO.4.58.0405251517200.6917 () organa ! utdallas ! edu
[Download RAW message or body]

Example of a simple but useful design, for what it's worth.

I have a MAIN controller that extends HttpServlet and gets the
function name to call from the request parameter "function". The value
for the function parameter is provided in the request URL or from a
hidden parameter (INPUT TYPE="hidden" NAME="function").

Each function class implements a WebFunction interface (my invention)
that has an execute method. This method does the appropriate work with
the session and VelocityContext based on the Http parameters, performs
logging, and returns the template name.  The Main controller
instantiates a function class based on the name given in the function
parameter, runs the execute method,and renders the template name
returned.

I like to have the execute method return a $state field that indicates
where the function is in it's life cycle and then render a "function"
template that looks kind of like:

#parse("head.vm")
$setForm  ## The <FORM ACTION=...> line
#set($function="Function")
<INPUT TYPE="hidden" NAME="function" VALUE="$function">
## $state indicates where it is in the function life-cyle
#if ($state=="start")
  #parse("welcome.vm")
#elseif ($state="done")
  #parse("done.vm")
#else
  #parse("welcome.vm")
#end
#parse("tail.vm")

The function's execute method itself does an entire subapplication
that may cover quite a few screens.  Having a function template like
the one above gives the web designer a lot of leeway in handling the
subapplication screen flow as it moves through the various steps.
This is done, of course, entirely with Velocity.

I've been able to do quite a bit with this simple design. These are
web applications used by my University to manage our computer
accounts.  It's not a mega-application, but it's not a hobby either.

Sorry, but there's nothing to see online, since all my applications
require login authentication and all functions require credential
certification.

Barbara Baughman
X2157


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic