apache > cocoon
 
Font size:      

Advanced Control Flow (2.1 legacy document)

Warning
This document was copied as is from the Cocoon 2.1 documentation, but has not yet been fully reviewed or moved to its new home.

Velocity Generator

If called from a Flowscript, the Cocoon Velocity Generator provides access to the immediate properties of the context object passed to cocoon.sendPage and cocoon.sendPageAndWait. In addition, the current WebContinuation is also available as a variable named $continuation. You would typically access its id:

  <form action="$continuation.id">
  

You can also reach previous continuations by using the getParent() function:

  <form action="$continuation.getParent().id" >
  

In addition the following implicit objects are always available in the Velocity context:

Request $request
The current Cocoon request
Response $response
The Cocoon response associated with the current request
Session $session
The Cocoon session associated with the current request
Context $context
The Cocoon context associated with the current request
org.apache.avalon.framework.parameters.Parameters $parameters
Any parameters passed to the generator in the pipeline

Cocoon installs a Velocity introspector that makes it possible for you to access JavaScript objects and arrays in your templates, as well as Java objects. For example, assuming you had a Flowscript like this:

    sendPage("myTemplate.vm", {colors: ["red", "blue", "yellow"]});
  

You could do this in myTemplate.vm:

    <select name="colors">
    #foreach ($color in $colors) 
      <option value="$color">$color</option>
    #end
    </select>
   

Comments

add your comments