Sylvain Wallez wrote: ....
<jx:when test="$widget.getWidget("items").size > 0">
Thanks for JXTemplateGenerator example. I assume $widget here should be woody form, which is stored in the request attribute, and according to [1], method call syntax is a bit different from the above. So I ended up with:
<jx:when test="getWidget(getAttribute($request, "form"), "items")/size > 0">
which actually worked for me, with JXTemplateGenerator. I'm now puzzled: how yours expression works?
It doesn't work ;-)
I wrote it by mimicing what's in Christopher's code without actually testing it.
Reading in more detail the JX implementation of <wt:form-template> and <wt:repeater>, I found that the variable containing the current widget is not "widget" but "ignored"!!
Christopher, can you confirm this? I would be good to have the "widget" or "currentWidget" variable available to crawl the widget tree from any point in the 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.
I'm worried a bit about performance of such a beastie - macros on top of interpreted jxpath language executed in interpreted java machine...
Yep. But this also avoids an additional transformer.
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".
Now I'm lost. I have not found code in neither EffectWidgetReplacingPipe nor in WoodyTemplateTransformer which would implement any jx: functionality, except commented-out translateText method. What do I miss?
Maybe I wasn't clear. A "regular" JXTemplate (without Woody macros) can access the form model to dynamically build the form template that's later expanded by WoodyTransformer.
But if we want to implement the repeater example (different layout depending on the repeater size) using this combination, we can do it only for top-level repeaters and not for nested ones, as the iteration on repeaters is handled by the transformer, and JXTemplate can therefore not access the properties of these nested repeaters (unless the JX template implements itself that iteration, but it is then equivalent to the macros).
Hope it's clearer.
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
