You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2005/10/14 15:28:37 UTC
[DAISY] Updated: Advanced Control Flow - JXTemplate
A document has been updated:
http://cocoon.zones.apache.org/daisy/legacydocs/511.html
Document ID: 511
Branch: main
Language: default
Name: Advanced Control Flow - JXTemplate (previously Advanced Control Flow)
Document Type: Document (unchanged)
Updated on: 10/14/05 1:28:21 PM
Updated by: Helma van der Linden
A new version has been created, state: publish
Parts
=====
Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name: (unchanged)
Size: 22304 bytes (previous version: 22345 bytes)
Content diff:
(20 equal lines skipped)
<tt>org.apache.cocoon.generation.JXTemplateGenerator</tt>, for example like
this:</p>
--- <pre>
--- <map:generators>
+++ <pre><map:generators>
<map:generator label="content,data"
logger="sitemap.generator.jx" name="jx"
src="org.apache.cocoon.generation.JXTemplateGenerator"/>
(17 equal lines skipped)
<p>Having an embedded expression language allows a page author to access an
object using a simple syntax such as</p>
--- <pre>
--- <site signOn="${accountForm.signOn}">
--- </pre>
+++ <pre><site signOn="${accountForm.signOn}">
+++ </pre>
<p>Embedded Jexl expressions are contained in <tt>${}</tt>.</p>
(9 equal lines skipped)
<ul>
<li><a href="daisy:518#request">request</a>: <br/>
The current Cocoon request</li>
--- <li><br/>
--- <a href="daisy:518#session">session</a>: <br/>
+++ <li><a href="daisy:518#session">session</a>: <br/>
The user session associated with the current request</li>
--- <li><br/>
--- <a href="daisy:518#context">context</a>: <br/>
+++ <li><a href="daisy:518#context">context</a>: <br/>
The Cocoon context associated with the current request</li>
--- <li><br/>
--- <tt>parameters</tt>: <br/>
+++ <li><tt>parameters</tt>: <br/>
A map containing the parameters passed to the generator in the pipeline</li>
--- <li><br/>
--- <a href="daisy:518#WebContinuation">continuation</a>: <br/>
+++ <li><a href="daisy:518#WebContinuation">continuation</a>: <br/>
The current Web Continuation from your Flowscript</li>
</ul>
<p>Jexl Example:</p>
--- <pre>
--- The content type of the current request is ${cocoon.request.contentType}
+++ <pre>The content type of the current request is ${cocoon.request.contentType}
</pre>
<p>JXPath Example:</p>
--- <pre>
--- The content type of the current request is #{$cocoon/request/contentType}
+++ <pre>The content type of the current request is #{$cocoon/request/contentType}
</pre>
<p>You would typically access the <tt>id</tt> of the Web Continuation:</p>
--- <pre>
--- <form action="${cocoon.continuation.id}">
+++ <pre><form action="${cocoon.continuation.id}">
</pre>
<p>You can also reach previous continuations via its <tt>parent</tt> property:
</p>
--- <pre>
--- <form action="${cocoon.continuation.parent.id}" >
+++ <pre><form action="${cocoon.continuation.parent.id}" >
</pre>
<p>or using an XPath expression:</p>
--- <pre>
--- <form action="#{$cocoon/continuation/parent/id}" >
+++ <pre><form action="#{$cocoon/continuation/parent/id}" >
</pre>
<p>Deprecated Variables:</p>
(32 equal lines skipped)
<p>Example:</p>
--- <pre>
---
--- <map:match pattern="*.jx">
+++ <pre> <map:match pattern="*.jx">
<map:generate type="jx" src="documents/{1}.jx">
<map:parameter name="lenient-xpath" value="true"/>
</map:generate>
<map:serialize type="xhtml"/>
</map:match>
---
</pre>
<h1>Tags</h1>
<p>The JXTemplate Generator tags are defined in the namespace</p>
--- <pre>
--- http://apache.org/cocoon/templates/jx/1.0
+++ <pre>http://apache.org/cocoon/templates/jx/1.0
</pre>
<h2>template</h2>
<p>The <tt>template</tt> tag defines a new template:</p>
--- <pre>
--- <jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
+++ <pre><jx:template xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
body
</jx:template>
</pre>
(4 equal lines skipped)
current template. The content of the imported template is compiled and will be
executed in place of the <tt>import</tt> tag:</p>
--- <pre>
--- <jx:import uri="URI" [context="Expression"]/>
+++ <pre><jx:import uri="URI" [context="Expression"]/>
</pre>
<p>The Cocoon source resolver is used to resolve <tt>uri</tt>. If
(7 equal lines skipped)
<tt>value</tt> attribute specifies the object (defaults to <tt>body</tt> if not
present):</p>
--- <pre>
--- <jx:set var="Name" [value="Value"]>
+++ <pre><jx:set var="Name" [value="Value"]>
[body]
</jx:set>
</pre>
(3 equal lines skipped)
<p>Jexl Example:</p>
--- <pre>
--- <jx:set var="greeting" value="Hello ${user}"/>
+++ <pre><jx:set var="greeting" value="Hello ${user}"/>
The value of greeting is ${greeting}
</pre>
<p>JXPath Example:</p>
--- <pre>
--- <jx:set var="greeting" value="Hello #{user}"/>
+++ <pre><jx:set var="greeting" value="Hello #{user}"/>
The value of greeting is #{$greeting}
</pre>
(2 equal lines skipped)
<p>The <tt>if</tt> tag allows the conditional execution of its body according to
value of its <tt>test</tt> attribute:</p>
--- <pre>
--- <jx:if test="Expression">
+++ <pre><jx:if test="Expression">
body
</jx:if>
</pre>
<p>Jexl Example:</p>
--- <pre>
--- <jx:if test="${cart.numberOfItems == 0}">
+++ <pre><jx:if test="${cart.numberOfItems == 0}">
Your cart is empty
</jx:if>
</pre>
<p>JXPath Example:</p>
--- <pre>
--- <jx:if test="#{cart/numberOfItems = 0}">
+++ <pre><jx:if test="#{cart/numberOfItems = 0}">
Your cart is empty
</jx:if>
</pre>
(6 equal lines skipped)
conditions of its nested <tt>when</tt> tags evaluate to <tt>true</tt>, then the
body of its <tt>otherwise</tt> tag is evaluated, if present:</p>
--- <pre>
--- <jx:choose>
+++ <pre><jx:choose>
<jx:when test="Expression">
body
</jx:when>+
(5 equal lines skipped)
<p>Jexl Example:</p>
--- <pre>
--- <jx:choose>
+++ <pre><jx:choose>
<jx:when test="${!user.loggedIn}">
<jx:set var="label" value="Log in">
</jx:when>
(5 equal lines skipped)
<p>JXPath Example:</p>
--- <pre>
--- <jx:choose>
+++ <pre><jx:choose>
<jx:when test="#{not(user/loggedIn)}">
<jx:set var="label" value="Log in">
</jx:when>
(8 equal lines skipped)
<p>The <tt>out</tt> tag evaluates an expression and outputs the result of the
evaluation:</p>
--- <pre>
--- <jx:out value="Expression"/>
+++ <pre><jx:out value="Expression"/>
</pre>
<p>Jexl Example:</p>
--- <pre>
--- <jx:out value="${cart.numberOfItems}">
+++ <pre><jx:out value="${cart.numberOfItems}">
</pre>
<p>JXPath Example:</p>
--- <pre>
--- <jx:out value="#{cart/numberOfItems}">
+++ <pre><jx:out value="#{cart/numberOfItems}">
</pre>
<h2>forEach</h2>
<p>The <tt>forEach</tt> tag allows you to iterate over a collection of objects:
</p>
--- <pre>
--- <jx:forEach [var="Name"] [varStatus="Name"] [items="Expression"]
+++ <pre><jx:forEach [var="Name"] [varStatus="Name"] [items="Expression"]
[begin="NumExpr"] [end="NumExpr"] [step="NumExpr"]>
body
</jx:forEach>
(13 equal lines skipped)
XPath (since you can specify the selection criteria for the collection using
XPath itself):</p>
--- <pre>
--- <jx:forEach select="XPathExpression">
+++ <pre><jx:forEach select="XPathExpression">
body
</jx:forEach>
</pre>
(3 equal lines skipped)
<p>Jexl Example:</p>
--- <pre>
--- <jx:forEach var="item" items="${cart.cartItems}"
+++ <pre><jx:forEach var="item" items="${cart.cartItems}"
begin="${start}" end="${count-start}" step="1">
<td>${item.productId}</td>
</jx:forEach>
</pre>
<p>JXPath Example:</p>
--- <pre>
--- <jx:forEach select="#{cart/cartItems[position() &lt;= $count]}}>
+++ <pre><jx:forEach select="#{cart/cartItems[position() &lt;= $count]}}>
<td>#{./productId}</td>
</jx:forEach>
</pre>
(4 equal lines skipped)
following properties:</p>
<table>
+++ <tbody>
<tr>
--- <td>
+++ <th>
<p>Property:</p>
--- </td>
--- <td>
+++ </th>
+++ <th>
<p>Description:</p>
--- </td>
+++ </th>
</tr>
<tr>
<td>
(59 equal lines skipped)
<p>The value of the <tt>step</tt> attribute</p>
</td>
</tr>
+++ </tbody>
</table>
<p>Jexl Example:</p>
--- <pre>
--- <jx:forEach items="${items}" varStatus="status">
+++ <pre><jx:forEach items="${items}" varStatus="status">
index=${status.index},
count=${status.count},
current=${status.current},
(6 equal lines skipped)
<p>JXPath Example:</p>
--- <pre>
--- <jx:forEach select="#{items}" varStatus="status">
+++ <pre><jx:forEach select="#{items}" varStatus="status">
index=#{$status/index},
count=#{$status/count},
current=#{$status/current},
(11 equal lines skipped)
locale, for example, whether to use a period or a comma for delimiting the
integer and decimal portions of a number. Here is its syntax:</p>
--- <pre>
--- <jx:formatNumber value="Expression"
+++ <pre><jx:formatNumber value="Expression"
[type="Type"] [pattern="Expression"]
[currencyCode="Expression"] [currencySymbol="Expression"]
[maxIntegerDigits="Expression"] [minIntegerDigits="Expression"]
(41 equal lines skipped)
<p>The <tt>formatDate</tt> tag provides facilities to format Date values:</p>
--- <pre>
--- <jx:formatDate value="Expression" [dateStyle="Style"]
+++ <pre><jx:formatDate value="Expression" [dateStyle="Style"]
[timeStyle="Style"] [pattern="Expression"] [type="Type"] [var="Name"]
[locale="Expression"]>
</pre>
(38 equal lines skipped)
<p>The <tt>macro</tt> tag allows you define a new custom tag.</p>
--- <pre>
--- <jx:macro name="Name" [targetNamespace="Namespace"]>
+++ <pre><jx:macro name="Name" [targetNamespace="Namespace"]>
<jx:parameter name="Name" [optional="Boolean"] [default="Value"]/>*
body
</jx:macro>
</pre>
<p>For example:</p>
--- <pre>
--- <jx:macro name="d">
+++ <pre><jx:macro name="d">
<tr><td></td></tr>
</jx:macro>
</pre>
<p>The tag being defined in this example is <tt><d></tt> and it can be
used like any other tag:</p>
--- <pre>
--- <d/>
+++ <pre><d/>
</pre>
<p>However, when this tag is used it will be replaced with a row containing a
(3 equal lines skipped)
available as variables in the body of the <tt>macro</tt>'s definition, for
example:</p>
--- <pre>
--- <jx:macro name="tablerows">
+++ <pre><jx:macro name="tablerows">
<jx:parameter name="list"/>
<jx:parameter name="color"/>
<jx:forEach var="item" items="${list}">
(13 equal lines skipped)
<p>and a template like this:</p>
--- <pre>
--- <table>
+++ <pre><table>
<tablerows list="${greatlakes}" color="blue"/>
</table>
</pre>
<p>When the <tt>tablerows</tt> tag is used in this situation the following
output would be generated:</p>
--- <pre>
--- <table>
+++ <pre><table>
<tr><td bgcolor="blue">Superior</td></tr>
<tr><td bgcolor="blue">Michigan</td></tr>
<tr><td bgcolor="blue">Huron</td></tr>
(10 equal lines skipped)
<a href="http://java.sun.com/products/jsp/jstl/">JSTL</a> <tt>forTokens</tt>
tag:</p>
--- <pre>
---
--- <jx:macro name="forTokens">
+++ <pre><jx:macro name="forTokens">
<jx:parameter name="var"/>
<jx:parameter name="items"/>
<jx:parameter name="delims"/>
(6 equal lines skipped)
<p>The tag produced by this macro can be used like this:</p>
--- <pre>
---
--- <forTokens var="letter" items="a,b,c,d,e,f,g" delims=",">
+++ <pre><forTokens var="letter" items="a,b,c,d,e,f,g" delims=",">
letter = ${letter} <br/>
</forTokens>
</pre>
<p>which would create the following output:</p>
--- <pre>
---
--- letter = a <br/>
+++ <pre> letter = a <br/>
letter = b <br/>
letter = c <br/>
letter = d <br/>
(6 equal lines skipped)
<p>The <tt>eval</tt> tag permits dynamic evaluation of custom tags.</p>
--- <pre>
--- <jx:eval select="Expression"/>
+++ <pre><jx:eval select="Expression"/>
</pre>
<p>Within the body of a macro, information about the current invocation is
available via a special variable <tt>macro</tt>. This variable contains the
following properties:</p>
<table>
+++ <tbody>
<tr>
--- <td>
+++ <th>
<p>Property:</p>
--- </td>
--- <td>
+++ </th>
+++ <th>
<p>Description:</p>
--- </td>
+++ </th>
</tr>
<tr>
<td>
(11 equal lines skipped)
<p>A reference to the content of the tag invocation</p>
</td>
</tr>
+++ </tbody>
</table>
<p>You can store the value of <tt>body</tt> in another variable and invoke it
(2 equal lines skipped)
</p>
<pre>
---
---
<jx:set var="tags" value="${java.util.HashMap()}"/>
<jx:macro name="dynamic-tag">
(14 equal lines skipped)
<p>The above template produces the following output:</p>
--- <pre>
+++ <pre><p>I'm about to invoke a dynamic tag:</p>
--- <p>I'm about to invoke a dynamic tag:</p>
---
<em>This tag was invoked dynamically</em>
(4 equal lines skipped)
Fields
======
no changes
Links
=====
no changes
Custom Fields
=============
no changes
Collections
===========
no changes