Hello Charles,

If your application is using the Model-1 approach where the .vm files are
specified in the URL's, you have a couple of options.

1.  Create a Bean or Action (extending ActionSupport) class.  In your
templates, use the #bean or #action macro respectively to instantiate the
class; set properties on the class and then execute it with the #execute
macro.

2.  If you have simple utility Beans that you need to make available on
many of the templates, using the #bean method may not be the best way. 
Instead, you could extend WebWorkVelocityServlet and override the
createContext method.  In that method, first call super.createContext to
get the WebWork initialized Velocity context.  Then you can add your own
objects to the context.  This will make these objects available to all
templates.  

If however, you are doing more substantive logic such as handling a form
post you probably want to use the Model-2 approach.  This allows much
better control and error handling.  Briefly, you would create a class
extending ActionSupport to handle your logic.  You would create one or
more entries in the actions.xml or views.properties to map the action to
the desired Velocity template (or JSP).  In your URL's you would specify a
URL to the Action.  This technique is outlined in the docs.  Although the
focus of the docs is JSP in this area, most all of it applies to Velocity
as well.

Also, in the velocity-dev mailing list, there's been an effort underway to
create a generic Velocity View servlet that can load tools via definitions
in an XML file.  At some point, it may make sense to integrate that with
the WebWorkVelocityServlet.

-Bill

"Charles N. Harvey III" wrote:
> 
> Hello.
> I have just downloaded WebWork 1.0 and am quite impressed.  And there are
> only
> a few questions that I need answered.  But I will do some searching of the
> archives before I post too many of them.
> 
> The one that is really nagging me is:
> Is it possible to add values to the default context?  I have been working
> with
> Velocity for some time and like the features that WebWork provides.  *.vm is
> mapped to the WebWorkVelocityServlet.  And there are objects like request
> and
> response in the context.  I would like to be able to add something like user
> information to this context.  The goal is an entire site with .vm pages so
> each
> of them can have access to server and user information that I decide upon.
> 
> So do I write a servlet that extends WebWorkVelocityServlet and load it in
> my web.xml?  Do I add a call in WebWorkVelocityServlet to my servlet?  And I
> would prefer to create a bean so that if a developer really wants to use a
> .jsp
> page for something he can access my values as part of the webwork taglib.
> 
> Thanks.
> 
> Charlie

_______________________________________________
Webwork-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webwork-user

Reply via email to