XWiki - Open Source Wiki and Content-Oriented Application Platform » FAQ » HowToListDocumentsWithACertainPropertyValue

HowToListDocumentsWithACertainPropertyValue

Last modified by Mattia Colagrossi on 2007/12/14
Question Can you create a page pointing to all pages with a certain property value?
Answer I figured out that it's possible to do this using velocity script:

* Get a list of documents using \$xwiki.searchDocuments().   This returns a list of document names in string format, not a list of document objects.
* Iterate through the list using a \#foreach statement.  For each result:
** use \$xwiki.getDocument($docname) to obtain the document object
** Then use the document.getObject(\$objectname) function to obtain the object you're interested in
** Finally use object.getProperty(\$propname).getValue() to obtain the value of the desired property, and use this to determine whether this document meets your criteria
Note: I had some problems with set statements, because if you try to set a variable to a null object, it seems to retain it's old value? So when iterating over pages which might not have a certain object, be careful to check the property directly.
Tags:
Created by starwed on 2006/01/14

Get Connected