Hi Ricardo,

> On 26 Feb 2017, at 13:49, [IDIS Technical Secretariat] Ricardo Rodríguez 
> <[email protected]> wrote:
> 
> Thanks, Vincent!
> 
> On Mon, Feb 20, 2017 at 1:28 PM Vincent Massol <[email protected]> wrote:
> 
>> Hi Ricardo,
>> 
>>> On 15 Feb 2017, at 09:02, [IDIS Technical Secretariat] Ricardo Rodríguez
>> <[email protected]> wrote:
>>> 
>>> Hi! After many years surviving with Velocity scripts, it is time to enjoy
>>> Groovy's magic! :-)
>> 
>> Great! :)
>> 
>>> Both XWiki sites and the web, in general, are crowded with sites/pages
>> with
>>> plenty of Groovy tutorials and manuals, but it would be great to have
>> some
>>> simple examples to helping understand the similarities and differences
>>> between Velocity and Groovy.
>>> 
>>> Please, is there any XWiki resource explaining, for instance, how to
>>> achieve the same results shown in these sections by using Groovy?
>> 
>> There’s this doc that you may or may not have seen already:
>> http://platform.xwiki.org/xwiki/bin/view/DevGuide/Scripting
>> 
>> Please check in this doc the limitations of using groovy (programming
>> rights).
>> 
>> It’s easy to convert a velocity script in groovy in general since the
>> bindings are the same and all the API calls are actually calls on java
>> objects and thus are the same from all scripting languages.
>> 
>> Let us know if you have specific questions
>> 
> 
> There is one line here...
> 
> http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide
> 
> ... that is making me nuts! This one...
> 
> SomeSpace.SomeClass[0] : field1 = "$rawValue"
> 
> I've been not able to make it work, whereas other syntaxes do. Here some
> "life" Groovy examples....
> 
> http://portal.idisantiago.es/xwiki/bin/view/ICT/Groovy/

These 2 lines seem wrong:

objsAuthors = doc.getObjects('XWiki.XWikiComments').author
objsAuthor = doc.getObjects('XWiki.XWikiComments')[2].author

doc.getObjects() will return a List of objects (i.e. several), and there’s no 
getAuthor() or get(‘author’) API on a Vector or List…

If you want to iterate you need to:

doc.getObjects('XWiki.XWikiComments’).each() {
  def author = it.get(‘author’)
  println “* ${author}"
}

I think the error is that in Velocity the call:

$doc.getObjects('XWiki.XWikiComments')[2].author is a shortcut and the real 
call is:

$doc.getObjects('XWiki.XWikiComments')[2].get(‘author’)

See http://velocity.apache.org/engine/1.7/user-guide.html#property-lookup-rules

This doesn’t exist in Groovy so you need to write get(‘author’).

Thanks
-Vincent



> 
> Please, how that line does work?
> 
> Thank you very much!
> 
> Ricardo
> 
> 
>> 
>> Thanks
>> -Vincent
>> 
>>> 
>> http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAccessobjectsinapage
>>> 
>>> 
>> http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAccessobjectsfromanypageandloopoverallobjectsofsameClass
>>> 
>>> Thanks for your help!
>>> 
>>> Ricardo
>>> --
>>> Ricardo Rodríguez
>>> Research Management and Promotion Technician
>>> Technical Secretariat
>>> Health Research Institute of Santiago de Compostela (IDIS)
>>> http://www.idisantiago.es
>> 
>> --
> Ricardo Rodríguez
> Research Management and Promotion Technician
> Technical Secretariat
> Health Research Institute of Santiago de Compostela (IDIS)
> http://www.idisantiago.es

Reply via email to