On 05/20/2011 08:55 PM, Karel Gardas wrote:
>
> Hello,
>
> for authoring template code like:
>
> ## You can modify this page to customize the presentation of your object.
> ## At first you should keep the default presentation and just save the
> document.
>
> #set($class = $doc.getObject('Book store.AuthorClass').xWikiClass)
> #foreach($prop in $class.properties)
> ; $prop.prettyName
> : $doc.display($prop.getName())
> : $prop.getName()
> #end
>
> is used by default. I need to modify this to extract some of the
> properties of the object and set it to the Xwiki context to be passed
> into another scripts, but besides #foreach I'm not able to extract
> individual properties from the properties collection by any possible
> way. Some of things I tried was (in my case I'm interested in "name"
> property)
>
> $class.properties.name
> $class.properties["name"]
> #set ($props = $class.properties)
> $props
> $props.name
> $props.get("name")
> $class.properties.getName()
> ($($class.properties).getName())
Keep in mind that there are real Java objects behind these variables,
and you can check the Javadoc (and even the source code) of those objects.
Printing $class.class reveals that you're dealing with an object of type
com.xpn.xwiki.api.Class, and checking the API at
http://platform.xwiki.org/xwiki/bin/view/DevGuide/API shows that the
method you're looking for is:
$class.get("name")
And it's a feature of Velocity to automatically try to use a "get"
method when a more specific method is not found, you can even do:
$class.name
Looking at what $class.properties returns, you can see that it's an
array of properties as in Element[], so you can't retrieve properties by
name from there.
> but so far w/o any success. On the other hand the code like:
>
> #foreach($prop in $class.properties)
> #if ($prop.getName() == "name")
> I FOUND THE NAME PROP!
> #end
> #end
>
> is working well, but is not that elegant as if properties would allow
> kind of map usage...
>
> Any help on this is highly appreciated.
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs