[ 
http://issues.apache.org/jira/browse/JELLY-167?page=comments#action_57993 ]
     
Marc DeXeT commented on JELLY-167:
----------------------------------

Hans Gilde said 
> I'm not sure about the TagCache, though. Do you have an example where you 
> need to inherit the tag cache?

Sure. If you take a look to my function tag library ( 
http://issues.apache.org/jira/browse/JELLY-193 ),  you could see that this tag 
assign to a context var his body :
+    /**
+     * @see 
org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
+     */
+    public void doTag(XMLOutput output) throws MissingAttributeException, 
JellyTagException {
+        if ( getVar() == null ) {
+            throw new MissingAttributeException("var");
+        }
+        
+        context.setVariable(getVar(),this);
+    }

and  this body is run later as in JSL tag library by a CallTag in Call method 

+    /**
+     * @see org.apache.commons.jelly.tags.util.CallableTag#call()
+     */
+    public List call(List arguments,XMLOutput output) throws 
MissingAttributeException, JellyTagException {
+        
+        returnList = new ArrayList(); 
+        
+        innerContext = new IsolatedJellyContext(context);
+        
+        transfertArgToContext(arguments);
+        try {
+            getBody().run(innerContext,output);
+        } catch( Exception e ) {
+            if ( ! (e instanceof ReturnException) ) {
+                throw new JellyTagException(e);
+            }
+        }
+        return returnList;
+    }

In the first tag body (FunctionTag), there's a ReturnTag which populate the 
Function return values list by searching his ancestor :

+    protected void doAction(XMLOutput output) throws MissingAttributeException,
+    JellyTagException {
+        
+        if ( tag == null ) {
+            tag = (CallableTag) findAncestorWithClass(CallableTag.class);
+        }
+        if ( tag == null ) {
+            throw new JellyTagException("Must be nested in CallableTag 
implementator");
+        }
+        
+        if ( getValue() != null ) {
+            tag.addReturn( getValue());
+        } else {
+            invokeBody(output);
+        }
+    }

So you have this kind of script :
<function var="myFunc"> // put his body as var
 (... body not executed on doTag(XmlOutput) but Call(List arguments,XMLOutput 
output)...)
  <return/> 
// - which will search his ancestor (so uses tag cache).
</function>

<call function="${myFunc}"/>

If you don't use _current context_ in FunctionTag Call(List arguments,XMLOutput 
output)...), but a _new_ context the ResultTag will search his ancestor in a 
empty tag cache, will don't find his ancestor :

(JellyContext)
    /** @return the tag associated to the given TagScript for the current run.
      */
    public Tag getTagOfTagScript(TagScript script) {
        if( script == null )
            return null;
        Tag tag = (Tag) tagHolderMap.get(script);
                if( tag == null && getParent() != null) {
                        return getParent().getTagOfTagScript(script);
                } else {
                        return tag;
   }

and so create a new tag : returnList will be not populated and Feature will 
fail!

If you want to test, apply patch 
http://issues.apache.org/jira/secure/attachment/18710/patch.functionRC_.2.txt

test, then, change in FunctionTag 
+    /**
+     * @see org.apache.commons.jelly.tags.util.CallableTag#call()
+     */
+    public List call(List arguments,XMLOutput output) throws 
MissingAttributeException, JellyTagException {
+        
+        returnList = new ArrayList(); 
+        
+        innerContext = new IsolatedJellyContext(context);
+        
+        transfertArgToContext(arguments);
+        try {
+            getBody().run(innerContext,output);
+        } catch( Exception e ) {
+            if ( ! (e instanceof ReturnException) ) {
+                throw new JellyTagException(e);
+            }
+        }
+        return returnList;
+    }


by 

+    /**
+     * @see org.apache.commons.jelly.tags.util.CallableTag#call()
+     */
+    public List call(List arguments,XMLOutput output) throws 
MissingAttributeException, JellyTagException {
+        
+        returnList = new ArrayList(); 

///////////// change here ///////////////////        
+        innerContext = new JellyContext(); 
///////////// change here ///////////////////        
+        
+        transfertArgToContext(arguments);
+        try {
+            getBody().run(innerContext,output);
+        } catch( Exception e ) {
+            if ( ! (e instanceof ReturnException) ) {
+                throw new JellyTagException(e);
+            }
+        }
+        return returnList;
+    }




> add 'public JellyContext newEmptyJellyContext()' to JellyContext
> ----------------------------------------------------------------
>
>          Key: JELLY-167
>          URL: http://issues.apache.org/jira/browse/JELLY-167
>      Project: jelly
>         Type: Wish
>   Components: core / taglib.core
>     Versions: 1.0-beta-5
>     Reporter: Marc DeXeT
>  Attachments: patch.function.2.txt
>
> method 'public JellyContext newJellyContext()' uses 'public 
> JellyContext(JellyContext parent)'.
> This constructor copies parent properties AND parent variables.
> To create variables quenched context, you have to clear variables or to set 
> inherit to false.
> I wish to have a new method 'public JellyContext newEmptyJellyContext()' 
> which copies all root context properties (as tag caching) but DOESN'T copy 
> variables map. 
> Even if you could do the same with inherit or variable map clearing or other 
> methods, it would be more meaningful to use a assigned method

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to