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

List:       velocity-user
Subject:    Re: VelocityViewServlet MVC
From:       Nathan Bubna <nathan () esha ! com>
Date:       2004-06-24 23:45:26
Message-ID: 001801c45a45$5400ac30$6b05a8c0 () zeus ! esha ! com
[Download RAW message or body]

Terry said:
> Hi, I'm new to the VelocityViewServlet, VVS, and I am looking for
> guidelines in how to develop a separation of my business objects that I
> place in VVS's request, session, or application scope and my view.

hmm.  yeah, i guess there's no good intro or best practices docu for this
anywhere.

> Right now, I place my business objects to my templates through the use
> of the toolbox.xml file.

typically, i create view tools that retrieve (aka "pull") the data i need out
of my business logic when it is requested by a template.  then i put my tools
in the toolbox rather than expose my business (aka model) objects directly.
see the section about tool scopes here
http://jakarta.apache.org/velocity/tools/view/  for more on deciding scope and
implementing the ViewTool interface.

> Traditionally I would use the old VelocityServlet and place all
> my business logic in the 'handleRequest' method.  Now, my question
> is how do I now place all my Java business logic to my template, .vm,
> file.

hmm.  i suppose you can do that if you really want, but i wouldn't recommend
it.  and be aware that the VVS's handleRequest() method isn't empty. :)

instead, i would recommend separating your interactive business logic (things
which create/edit/update/delete data in your model) into a different servlet
that forwards requests on to velocity templates when it is done with them.  in
other words, map the VVS to all *.vm files.  fill your toolbox.xml with the
tools you need to view and/or format your data for display.   then set up a
second servlet to handle "action" business logic like submitting, rearranging,
updating, or deleting data.  i have found this development pattern to be very
quick, easy, and secure.

> Where do I put my Java Code?

java needed to view data can be put into custom view tools.

> Is all business logic placed in the toolbox?

that's a bad idea if you ask me.

> and wouldn't placing so many business objects into the toolbox
> to be available to every other template, .vm, slow down my performance?

it certainly could.

> And, how would my Toolbox methods get a reference to the request,
> response, and ServletConfig objects?

by implementing the ViewTool interface.  look at the source for the tools in
the VelocityView or VelocityStruts packages for examples of these things.

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
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