Below I have listed a pure WM template solution for debugging
context and link parameters (could be enhanced to contain
session parameters as well).

This is *t*h*e* solution for the previous email in this thread
"Re: Debug features of Cold Fusion". Maybe this avoids requiring 
turbine users to re-invent the wheel ;-)

Comments and enhancements are welcome.
(Specifically it would be nice to make the variables in 
 the dump table clickable to dump that specific variable
 using reflection - similar to the Tea application).

:) Christoph

The debug.wm code is listed further below.
----- Add this to the layout or navigation_bottom -----
#if ($debug) #begin
  #set $dummy = $data.getParameters().remove("debug");
  <a href="$link.toString($data)">disable debug dump</a>
  #parse "debug.wm"
#end #else #begin
  #set $dummy = $data.getParameters().add("debug", true);
  <a href="$link.toString($data)">enable debug dump</a>
#end
-------------------------------------------------------

Use this code to take the debug flag from the query string:
---------- snippet: save debug flag in link ------------
#set $debug = $data.getParameters().getBoolean("debug")
#if ($debug) #begin
  ## promote the state into further links
  #set $dummy = $link.addQueryData("debug", 1)
  ## note that the link contents are lost after a toString()
#end
-------------------------------------------------------

Alternatively one could save the debug flag state into 
the session object (untested code):
--------- snippet: save debug flag in session ---------
## get the debug flag state from the session (false is the default)
#set $debug = $formatter.isNull($data.session.getValue("debug"), false)
## overlay the debug flag with possible value from the QueryString
#set $debug = $data.getParameters().getBoolean("debug", $debug)
## promote the state into the session
#set $dummy = $data.session.putValue("debug", $debug)
-------------------------------------------------------


This is the code that dumps the WM context variables:
--------------------- debug.wm ------------------------
## make the parameters visible in the dump
#set $pp = $data.getParameters()
## this line may be adapted to velocity 
## (note that the velocity context does not yet allow listing the keys)
#set $globalMap = 
$data.getTemplateInfo().getTemplateContext("WEBMACRO_CONTEXT").getGlobalVariables()
<br><font size="+1"><b>Context Variables:</b></font><br>
<table cellspacing="0" cellpadding="0">
#foreach $foo in $globalMap.keySet().toArray()
{
  #set $value = $globalMap.get($foo)
  #set $type = $value.getClass().getName()
  <tr>
    <td><tt>$foo</tt></td>
    #if ( $type.startsWith("java.lang.") ) #begin
      #set $value = $value.toString()
      #set $type = $type.substring(10)
    #end #else #begin
      #if ( $type.equals("org.apache.turbine.util.ParameterParser") ) #begin
        #set $value = $value.toString()
        #set $type = "pp"
      #end #else #begin
        #set $value = $type
        #set $type = "="
      #end
    #end
      <td><tt>&nbsp;$type</tt></td>
      <td><tt>&nbsp;$value</tt></td>
  </tr>
}
</table>
<font size="2">Done.<br></font>
-------------------------------------------------------

:) Christoph


------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to