cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sylvain Wallez <sylv...@apache.org>
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:

<wt:form-template>
  <jx:choose>
    <jx:when test="$widget.getWidget("items").size > 0">
      There are no items in your cart.
      <wt:widget id="addItem"/>
    </jx:when>
    <jx:otherwise>
      <table>
        <tr>
          <th>Item</th>
          <th>Select</th>
        </tr>
        <wt:repeater-widget id="items">
          <tr>
            <td><wt:widget id="item"></td>
            <td><wt:widget id="select"></td>
          </tr>
        </wt:repeater-widget>
        <wt:widget id="addItem"/>
        <wt:widget id="removeItem"/>
      </table>
    </jx:otherwise>
  </jx:choose>
</wt:form-template>

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

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



Mime
View raw message