Kevin_C wrote:
I have a class in one of my spaces that has instances
of itself attached. Eg.
MySpace
MySpace.TopicsClass
MySpace.TopicsClass[0]
MySpace.TopicsClass[1]
How can I get the class from the space? I've tried:
#set ($hql = ", BaseObject as obj where obj.name = doc.fullName and
obj.className = 'FranchiseTax.TopicsClass' and
doc.space='FranchiseTax'")
#set($topics = $xwiki.searchDocuments($hql))
Topics comes back with one item, which I can see by displaying
$topics.get(0) and it prints out MySpace.TopicsClass. So it appears to have
returned a string name of the document, however when I try:
#set($topicObj = $xwiki.getDocument($topics.get(0)))
Nothing is set into $topicObj. Do I have to do something different if the
thing I am trying to get is a class and not a document? Once I have the
class how do I get the collection of associated objects?
$xwiki.searchDocuments returns a list of document names (well, it is called
"search documents"), and not objects or classes. The query does filter only
the documents that do have the objects you're interested in, you'll just have
to access them using the API, starting from the document name.
## Iterate over all documents having that type of objects
#foreach($documentName in $xwiki.searchDocuments($hql))
## Here documentName is a string, the name of the document
#set($documentObject = $xwiki.getDocument($documentName))
## Now you have a Document API,
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xw…
## Iterate over the objects found in this document
#foreach($object in $documentObject.getObjects('FranchiseTax.TopicsClass'))
## Display object properties with one of:
$object.display('propertyname', 'view')
$object.display('propertyname', 'edit')
$documentObject.display('propertyname', $object
## ... or other display methods from the Document class.
#end
#end
--
Sergiu Dumitriu
http://purl.org/net/sergiu/