Sorry for cross posting to turbine list, this deals mainly 
with turbine issues, but is a response to a velocity thread.

I agree with your points, but I'm looking for a simple way
of reusing the WM/VTL to do template configuration. These scripting
languages are powerfull enough to do what normally is needed.
Note that the #call directive will not be used within the view
template but within the configration template, thus probably
a ContextTool available to the configuration template is more 
apropiate.

Using the same template language for the configuration avoids
administrators and designers to have to learn two different
dialects. I like the power and simplicity of WM/VTL (WM could 
do without the #begin derective as VL does!).

Due to the fact that currently you need to write a java class 
to populate the context with variables and tools, it is not 
very flexible to administer. Instead of doing 
        context = getContext();
        context.put ( "data", data );
        context.put ( "link", new TemplateLink(data) );
        context.put ( "page", new TemplatePageAttributes(data) );
plus adding additional contexts within a java class matching
the requested template (or the Default class).
I'm thinking of - during service initialization:
        staticContext = getContext();
        loadContext("control/init.vm", staticContext);
for each request:
        context = getContext();
        // ... copy staticContext into per-request context ...
        loadContext("control/default.vm", context);
Then the control template corresponding to the request is loaded,
the special control ContextTools are removed, and therafter the 
normal screen and layout is performed. Note that this second 
request.vm call could be placed as a #parse in the normal control
template.

For you to get an idea of what I'm doing I've included a sample
below. Note the many "#set $dummy=" in there! The template will 
be split up into init and default processing parts.

I know that similar processing chains could be done with JSP or
Tea, but the #parse (within conditionals) is better than servlet
chaining for HMVC designs. And the JJJs (Jon/Justin/JasonH) have 
convinced me that WM has a more apropiate syntax for templates :)

Cheers,
Christoph

Jon Stevens wrote:
> 
> on 10/18/2000 11:48 AM, "Justin Wells" <[EMAIL PROTECTED]> wrote:
> 
> > In WM it's trivial to write a pluggable directive to allow
> > "#call $foo.exec()" and ignore the output. But adding that
> > to the langauge would violate the MVC design. You could easily
> > add it, but it's not in the core for a reason.
> 
> Right, it is possible to do that in Velocity as well.
> 
> > I see support for this kind of thing as a giant step backwards,
> > instead use ContextTools and other things provided to you that
> > don't violate the overall design.
> 
> I agree.
> 
> > If you want to call a lot of functions in your page you should
> > probably use JSP.
> 
> Or Tea. :-)
> 
> -jon

------------------ sample control/default.wm template ------------
## constants to be included in every screen via parse directive
##
## deine the default string for the $formatter.isNull() function
#set $NULL = ""
##
## define color look-up-tables
#set $COLORS = $util.makeHashtable()
#set $COLORS.BG = $util.makeHashtable()
#set $COLORS.FG = $util.makeHashtable()
##
## define body colors
#set $COLORS.BODY  = "#FFFFFF"  ## white
#set $COLORS.TEXT  = "#000000"  ## black
#set $COLORS.LINK  = "#0000EE"  ## dark blue
#set $COLORS.VLINK = "#551A8B"  ## dark violett
#set $COLORS.ALINK = "#FF0000"  ## red
##
## table and button border definitions
#set $COLORS.BORDER   = "#666666"  ## dark gray
#set $COLORS.HILITE   = "#EEEEEE"  ## light gray
#set $COLORS.BG.TEXT  = "#CCCCCC"  ## gray
#set $COLORS.FG.TEXT  = "#000000"  ## black
#set $COLORS.BG.TABLE = $COLORS.BG.TEXT
#set $COLORS.FG.TABLE = $COLORS.FG.TEXT
#set $COLORS.BG.HEAD  = "#003399"  ## dark blue
#set $COLORS.FG.HEAD  = "#FFFFFF"  ## white
#set $COLORS.BG.INFO  = "#008080"  ## dark green
#set $COLORS.FG.INFO  = "#FFFF00"  ## yellow
#set $COLORS.BG.WARN  = "#333300"  ## brown
#set $COLORS.FG.WARN  = "#FFFF00"  ## yellow
#set $COLORS.BG.ERROR = "#990000"  ## dark red
#set $COLORS.FG.ERROR = "#FFFF00"  ## yellow
##
## Service definitons
#set $SERVICES = $util.makeHashtable()
#set $SERVICES.ALL  = "ALL"
#set $SERVICES.LIST = [$SERVICES.ALL, "GDS", "SDS", "UMS", "IDS", "PBS", "OFS", "DSM"]
#set $SERVICES.NAME = $util.makeHashtable()
#set $SERVICES.NAME.ALL = "ALL MUIS Services"
#set $SERVICES.NAME.GDS = "Guide &amp; Data Server"
#set $SERVICES.NAME.SDS = "Service &amp Directory Server"
#set $SERVICES.NAME.IDS = "Inventory &amp; Data Server"
#set $SERVICES.NAME.PBS = "Product &amp; Browse Server"
#set $SERVICES.NAME.OFS = "Order Facility Service"
#set $SERVICES.NAME.UMS = "User Managment Service"
#set $SERVICES.NAME.DSM = "Distributed Service Management"
##
##
## assign default colors to the page
#set $page.BgColor    = $COLORS.BODY
#set $page.TextColor  = $COLORS.TEXT
#set $page.LinkColor  = $COLORS.LINK
#set $page.VlinkColor = $COLORS.VLINK
#set $dummy = $page.addAttribute("alink", $COLORS.ALINK)
##
##
## retrieve the service parameter and ensure it is valid
#set $service = $data.Parameters.getString("service", $SERVICES.ALL)
#set $notFound = true
#foreach $_serviceId in $SERVICES.LIST #begin
    #if ($_serviceId == $service) #begin
        #set $notFound = false
    #end
#end
#if ( $notFound ) #begin
    #set $service = $SERVICES.ALL
#end
#set $dummy = $util.Context.remove("_serviceId")
#set $dummy = $util.Context.remove("notFound")
#set $dummy = $link.addQueryData("service", $service)
##
#set $task = $data.getParameters().getString("task", "")
##
#set $template = $data.getTemplateInfo().getScreenTemplate()
##
##
## propagate the debug flag into following screens
#set $debug = $data.getParameters().getBoolean("debug")
#if ($debug) #begin
  #set $dummy = $link.addQueryData("debug", 1)
#end
##
##
## following might need to be redone after action processing:
#set $requestURL = $link.setPage($template).getURL()
## note .getURL() is a new function to TemplateLink since
## its toString() clears the QueryString and PathInfo parts.
------------------------------------------------------------------

------------------- sample control template ----------------------
#parse "defaults.inc.wm"
##
#set $_action = $data.getParameters().getString("submit", "")
##
## ------------------- action ----------------------
#if ( $_action == "Start Export" ) #begin
<br>action = Start Export
  #set $dummy = $data.getParameters().add("status", "true")
  #set $dummy = $data.getParameters().add("update", "true")
#end
#set $_status = $data.getParameters().getBoolean("status")
#if ( $_status ) #begin
  #set $dummy = $link.addQueryData("status", "true")
#end
##
## ------------------- action ----------------------
#set $_abort = false
#if ( $_action == "Abort" ) #begin
<br>action = Abort
  #set $_abort = true
  #set $dummy = $data.getParameters().remove("update")
#end
##
## ------------------- action ----------------------
#if ( $_action == "Hide Log" ) #begin
<br>action = Hide Log
  #set $dummy = $data.getParameters().remove("showlog")
#end
#if ( $_action == "Show Log" ) #begin
<br>action = Show Log
  #set $dummy = $data.getParameters().add("showlog", "true")
#end
#set $_showLog = $data.getParameters().getBoolean("showlog")
#if ( $_showLog ) #begin
  #set $dummy = $link.addQueryData("showlog", "true")
#end
##
## ------------------- action ----------------------
#if ( $_action == "Stop Update" ) #begin
<br>action = Stop Update
  #set $dummy = $data.getParameters().remove("update")
#end
#if ( $_action.endsWith("Automatic Update") ) #begin
<br>action = Automatic Update
  #set $dummy = $data.getParameters().add("update", "true")
#end
#set $_update = $data.getParameters().getBoolean("update")
#if ( $_update ) #begin
  #set $dummy = $link.addQueryData("update", "true")
#end
#set $_interval = $data.getParameters().getInteger("interval", 0)
#if ($_interval != 0) #begin
  #set $dummy = $link.addQueryData("interval", $_interval)
#end #else #begin
  #set $_interval = 5
#end
##
## ------------- freeze final URL --------------
#set $serviceURL = $link.setPage($template).toString()
##
## ------------- set refresh header ------------
#if ( $_update ) #begin
  #set $dummy = $page.setHttpEquiv("refresh", "$(_interval); $serviceURL")
#end
##
## --------- select the screen to use ----------
#if ( $_status ) #begin
  #set $dummy = $data.setScreen("status.wm")
#end #else #begin
  #set $dummy = $data.setScreen("form.wm")
#end
------------------------------------------------------------------
I will be desinging a ContextTool with call and new functionality
(Ugh, I'll be duplicating the parameter matching code for method
and constructor finding - jvz, note I sent you those code snippets,
- Justin, I saw that WM uses a caching mechanism for it - wow!).

Some questions:
* Why is WM (and VL) emmiting some new lines into the output,
  Seems that they comre from the ## comments to the colors.
* Why is WM swallowing the semicolon after the $(_interval) 
  invocation?

:) Christoph

Reply via email to