Dashboard > Hippo CMS > ... > 03. Developing templates > Template Business Logic definition
Template Business Logic definition
Added by Jeroen Reijn, last edited by Jasha Joachimsthal on Oct 30, 2007  (view change)
Labels: 


Defining the Business Logic for a template

The business logic file is mainly used to define:

  • internationalized labels for fields.
  • datasources for populating multivalue fields.
  • validation for fields.
  • custom code libraries, i.e. Javascript codebases.
  • directives for proper storage of fields.
  • data conversion upon storage or loading of documents.
  • pickers, i.e. pick values from custom lists, which are stored in CSV format.
  • event handling, i.e. on-insert of a row, execute some code.

The Business Logic file consists of a set of statements, which can basically be divided in three classes:

  • global definitions, which affect all fields
  • type definitions, which affect all fields of a particular type (the type refers to the XML schema type)
  • element definitions, which affect a single field

How does it work?

Example:

<businesslogic>

  <i18n>
    <field-prefix>cms.demo.fields</field-prefix>
    <help-prefix>cms.demo.help</help-prefix>
  </i18n>

  <libs>
    <!-- declare a code library
         'src' is a html uri, in this case the javascript file is generated via our
         project-specific sitemap.
      -->
    <lib src="/project-specific/js/htmlarea.js"/>
  </libs>

  <!-- for htmlarea you need to define 2 business logic rules :
       1. a binding-class; a java class which converts the results of the 'htmlarea' form element
           to valid xml
       2. htmlcleaner convertor; filters out invalid HTML elements.
       -->
  <rule for="/root/body">
    <binding-class>nl.hippo.cocoon.forms.binding.HTMLAreaBinding</binding-class>
    <convertor type="htmlcleaner"  config="cocoon://project-specific/resources/xml/HtmlCleanerConfiguration.xml" use="datamodel"/>
  </rule>

  <!-- binding-javascript was added in 6.06, 
       both load-form and save-form are required -->
  <rule for="/root/lookup/@id">
    <value-lookup source-id="lookup"/>
    <picker id="lookup"/>
    <binding-javascript>
      <save-form>
        var formValue = widget.getValue();
        var appValue = doSomeSaveConversion(formValue);
        jxpathPointer.setValue(appValue);
      </save-form>
      <load-form>
        var appValue = jxpathPointer.getValue();
        var formValue = doSomeLoadConversion(appValue);
        widget.setValue(formValue);
      </load-form>
    </binding-javascript>
  </rule>

</businesslogic>

As you can see the rule for an element is based on the XPath for that specific element.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.7 Build:#813 Aug 28, 2007) - Bug/feature request - Contact Administrators