cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <>
Subject Re: Woody template transformer using jx macros
Date Mon, 05 Jan 2004 08:51:18 GMT
Vadim Gritsenko wrote:

> Sylvain Wallez wrote:
>> Christopher Oliver wrote:
>>> Continuing my conversation with myself....
>> Well, continue, this conversation is very interesting ;-)
>> Seriously, having woody templates in a generator is IMO a must have, 
>> as there are many cases where just "inserting" widgets is not enough, 
>> and the page structure depends on the properties of the widgets.
>> An example is repeaters, where we may want a different display for 
>> empty repeaters and non-empty repeaters.
> Can you guys show a quick example of this? I'm not quite following all 
> the new development here...

Consider the classical shopping cart. The form has an "items" repeater 
containing an "item" field and a "select" boolean field. Two actions 
manage the shopping cart: "addItem" and "removeItem".

When the cart is empty, we don't want to show a table with only headers 
nor the "removeItem" button. The template may then be something like:

    <jx:when test="$widget.getWidget("items").size > 0">
      There are no items in your cart.
      <wt:widget id="addItem"/>
        <wt:repeater-widget id="items">
            <td><wt:widget id="item"></td>
            <td><wt:widget id="select"></td>
        <wt:widget id="addItem"/>
        <wt:widget id="removeItem"/>

The important difference with the WoodyTransformer is that the generator 
has access to the form model and therefore can produce a page layout 
whose content depend on the actual values of this model.

The above example is however a bit too simplistic since the same result 
could be achieved with the WoodyTransformer. The jx:when test expression 
would then be something like "$woody-form.getWidget("items").size > 0".

But in the case of nested repeaters, only the generator approach allows 
to have a form layout that depends on the properties of child repeaters, 
since the child repeater to be considered depends on the iteration index 
on the parent repeater.

Hope I was clear and it explains the use case!


Sylvain Wallez                                  Anyware Technologies 
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -

View raw message