Re: [xwiki-users] How to access util binding from velocity
Do you really need a utility class? I just tried this:
Not explicitly no.
{{velocity}} #set($map = {'name':'marius'}) $map.name {{/velocity}}
The problem is that I don't seem to be able to update a map created that way. If I try: {{velocity}} #set($map = {'name':'marius'}) $map.put('myname','adam') $map.name {{/velocity}} It fails. Whereas if I use a map from elsewhere (xcontext for example) and pass it in it seems to work just fine. I may be missing something obvious, that happens a lot! Cheers, Adam
On 02/03/2011 03:45 PM, [email protected] wrote:
Do you really need a utility class? I just tried this:
Not explicitly no.
{{velocity}} #set($map = {'name':'marius'}) $map.name {{/velocity}}
The problem is that I don't seem to be able to update a map created that way. If I try:
{{velocity}} #set($map = {'name':'marius'})
$map.put('myname','adam')
Do you want to overwrite the 'name' key or add a new key 'myname'?
$map.name {{/velocity}}
It fails. Whereas if I use a map from elsewhere (xcontext for example) and pass it in it seems to work just fine.
What do you mean by "fail"? If I try: {{velocity}} #set($map = {'name':'marius'}) $map.put('name','adam') $map.name and $map.myname {{/velocity}} I get: marius adam and $map.myname which is normal because $map.myname is null (was not set). If I try: {{velocity}} #set($map = {'name':'marius'}) $map.put('myname','adam') $map.name and $map.myname {{/velocity}} I get: $map.put('myname','adam') marius and adam which is normal because the put method returns the previous value mapped to the specified key, which is null in our case. It's better to write: #set($discard = $map.put('myname','adam')) Hope this helps, Marius
I may be missing something obvious, that happens a lot!
Cheers,
Adam
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (2)
-
Marius Dumitru Florea -
xwikiadmin@lazypapertiger.org