Apache » Cocoon »

  Cocoon Template
      1.0
   homepage

Cocoon Template 1.0

Expression Languages

The JXTemplate Generator supports two embedded expression languages: Jexl and JXPath. Apache Jexl provides an extended version of the expression language of the JSTL. Apache JXPath provides an interpreter of the XPath expression language that can apply XPath expressions to graphs of Java objects of all kinds: JavaBeans, Maps, Servlet contexts, DOM etc, including mixtures thereof.

Having an embedded expression language allows a page author to access an object using a simple syntax such as

<site signOn="${accountForm.signOn}">

Embedded Jexl expressions are contained in ${}.

Embedded JXPath expressions are contained in #{}.

The referenced objects may be Java Beans, DOM, or JavaScript objects from a Flowscript. In addition, a special cocoon object providing access to the Cocoon FOM is available as both a JXPath and Jexl variable in a template.

The cocoon object contains the following properties:

  • request

    The current Cocoon request
  • session

    The user session associated with the current request
  • context

    The Cocoon context associated with the current request
  • parameters:

    A map containing the parameters passed to the generator in the pipeline
  • continuation

    The current Web Continuation from your Flowscript
  • settings

    The Cocoon settings object holds the global configuration of Cocoon.
Jexl Example:
The content type of the current request is ${cocoon.request.contentType}
JXPath Example:
The content type of the current request is #{$cocoon/request/contentType}
You would typically access the id of the Web Continuation:
<form action="${cocoon.continuation.id}">
You can also reach previous continuations via its parent property:
<form action="${cocoon.continuation.parent.id}" >
or using an XPath expression:
<form action="#{$cocoon/continuation/parent/id}" >
Deprecated Variables:

The following variables are deprecated but still supported:

Note: When used inside flow, JXTemplate has access to Java and can therefore evaluate expressions like "java.util.Date()" or "java.util.HashMap()". This does NOT work when JXTemplates are used without flow. Some symptoms:

[*<jx:out value="${java.util.Date()"/>*] results in [**]
Note: <jx:formatDate value="${java.util.Date()}" pattern="yyyyMMdd"/> results in 'Cannot format given Object as a Date'
Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).