cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leszek Gawron <lgaw...@mobilebox.pl>
Subject Re: svn commit: r325889 - /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
Date Mon, 17 Oct 2005 15:33:29 GMT
Bruno Dumon wrote:
> On Mon, 2005-10-17 at 16:50 +0200, Leszek Gawron wrote:
> 
>>bruno@apache.org wrote:
>>
>>>Author: bruno
>>>Date: Mon Oct 17 06:24:48 2005
>>>New Revision: 325889
>>>
>>>URL: http://svn.apache.org/viewcvs?rev=325889&view=rev
>>>Log:
>>>Convert some Jexl expressions to JXPath so that they work also when used without
javascript-flow.
>>>
>>>Modified:
>>>    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
>>>
>>>Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
>>>URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml?rev=325889&r1=325888&r2=325889&view=diff
>>>==============================================================================
>>>--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
(original)
>>>+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
Mon Oct 17 06:24:48 2005
>>>@@ -87,7 +87,7 @@
>>>       <jx:if test="${cformsHelper.pushRepeater(id, false)}">
>>>         <jx:set var="repeater" value="${cformsHelper.peekWidget()}"/>
>>>         <jx:forEach varStatus="repeaterLoop" begin="0" end="${repeater.getSize()
- 1}">
>>>-          <jx:if test="${cformsHelper.pushContainer(java.lang.Integer.toString(repeaterLoop.index))}">
>>>+          <jx:if test="#{pushContainer($cformsHelper, java.lang.Integer.toString($repeaterLoop/index))}">
>>
>>I do not get it: why do you think this change is necessary? Does it 
>>break when used with JEXL ?
> 
> 
> It breaks when the template is not executed via a sendPage call from
> rhino flowscript (e.g. from an apple, or a directly called pipeline).
> 
> This is because jexl in itself does not allow to call static methods
> like java.lang.Integer.toString. The "java" is a special variable
> inserted into the jexl context by the jx template generator, and is only
> available when called from flow (since it is a rhino object). It would
> be possible to make something equivalent for when not using rhino, but
> the above is a quicker solution.
you are right but you are wrong :) You are right Jexl alone does not 
support java.* syntax. Still even if not used from flow we enrich object 
model with following data (TemplateObjectModelHelper.java):

> /**
>  * Add java packages to object model. Allows to construct java objects.
>  * @param objectModel usually the result of invoking getTemplateObjectModel
>  */
> public static Object addJavaPackages( Map objectModel ) {
>     Object javaPkg = FOM_JavaScriptFlowHelper.getJavaPackage(objectModel);
>     Object pkgs = FOM_JavaScriptFlowHelper.getPackages(objectModel);
>     
>     // packages might have already been set up if flowscript is being used
>     if ( javaPkg != null && pkgs != null ) {
>         objectModel.put( "Packages", javaPkg );
>         objectModel.put( "java", pkgs );
>     } else { 
>         Context cx = Context.enter();
>         try {
>             final String JAVA_PACKAGE = "JavaPackage";
>             ClassLoader cl = Thread.currentThread().getContextClassLoader();
>             Scriptable newPackages = new NativeJavaPackage( "", cl );
>             newPackages.setParentScope( getScope() );
>             newPackages.setPrototype( ScriptableObject.getClassPrototype(   getScope(),
>                                                                             JAVA_PACKAGE
) );
>             objectModel.put( "Packages", newPackages );
>             objectModel.put( "java", ScriptableObject.getProperty( getScope(), "java"
) );
>         } finally {
>             Context.exit();
>         }
>     }
>     return objectModel;
> }

You should see no difference when using JEXL from flow or without one. 
If I am wrong - this is clearly a bug.



-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Mime
View raw message