Nathan,

On 6/2/2011 4:17 PM, Nathan Bubna wrote:
> 2011/6/2 Șergiu Dumitriu <ser...@xwiki.com>:
>> On 06/02/2011 05:55 PM, Nathan Bubna wrote:
>>>
>>> Hi Andreas,
>>>
>>> Sorry to have inconvenienced you with this change.  The old behavior
>>> was causing problems and had some notable flaws (see my discussion of
>>> the quirks in https://issues.apache.org/jira/browse/VELOCITY-681).
>>> There are no clean workarounds to recover the proxying behavior.  You
>>> can set the original reference directly if you know it, of course, but
>>> that could get messy if a variety of references are passed in.   You
>>> might also restructure to pass in references to objects or maps so
>>> that changes to the referenced variable are seen in the original
>>> reference when #set on the macro argument reference to that variable.
>>> I know neither of these is ideal.
>>
>> There is a trick that can be used to achieve the old behavior. I've detailed
>> the problem here:
>> http://www.xwiki.org/xwiki/bin/ReleaseNotes/ReleaseNotesXWikiEnterprise30#HMacroevaluationstrategy
>>
>> The solution is to use #evaluate to set the new value to the original
>> reference. The loophole that allows this to work is that
>> "$formalParameterName" expands to "$actualParameterName" when
>> $formalParameter is undefined/null.
>>
>> I've written a macro that does this:
>> https://github.com/xwiki/xwiki-platform/blob/e9051c85ae78fb973f4edbaa968db6bf235eb582/xwiki-platform-core/xwiki-platform-web/src/main/webapp/templates/macros.vm#L1131
>> You use it by first setting the formal parameter to null, then calling
>> #setVariable("$formalParameterName" $value).
>>
>> By the way, will the loophole be preserved in future versions as well, or is
>> it in danger of being "fixed" at some point?
> 
> Oooh.  That's a neat trick.  I hadn't thought of that.  As for the
> future, the loophole won't go anywhere in 1.x so long as i'm paying
> attention.

Instead of relying on your (impeccable, I'm sure) attention, we could
create a unit test specifically for this behavior.

-chris

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to