Toolbox.xml - Documentation topics on: tab-libs,taglib,toolbox,toolbox.xml,velocity,viewtool,viewtools,.


Viewtools are just plain java POJOs that are mapped to all velocity contexts in dotCMS. You can think of Viewtools as  "tablibs" for velocity - like taglibs expose java methods to JSPs, so do Viewtools.  Viewtools are defined in the xml file


Mapping a java class as a Viewtool takes a key, a scope and the java class that the viewtool maps to.

The key can be referenced in any velocity code with a $, so to call the math tool, you just write $math and you have a handle on the object and the methods therein.

The scope defines when an instance of the tool will be instantiated.  It takes one of three possible values -

  • application : Viewtool will be a Singleton within the Application and should be thread safe.  These objects are instantiated once and reused across requests and contexts.
  • request : An instance of the Viewtool is instantiated with every request. Request viewtools have access to the server's HttpServletRequest and HttpServletResponse objects and can call methods in those objects in their code.
  • session : An instance of the Viewtool is instantiated and stored in the user session

The class is just the fully qualified class name

The easiest way to develop and add custom Viewtools to your dotCMS installation is to create an OSGi plugin.  Please see Example Plugin: Custom Velocity Viewtool for more information.

Below is the dotCMS toolbox.xml mapping taken directly from github as of Dec 5, 2016 5:30:32 AM and you can see how each tool is mapped in dotCMS.