Hi Martin, On 10/20/2010 09:10 PM, mbryant wrote:
So using HQL in velocity helps a little, I have been able to get results, and for that I thank you. I did run into an unexpected issues that you might be able to help with. Below is the query that was used
{{velocity}}
#set($hql = "select obj.name, prop.value from BaseObject obj, StringProperty prop where obj.className='CustClasses.ToolClass' and prop.id.id=obj.id and prop.name='ProductName'")
#set($results = $xwiki.search($hql, 1000, 0)) #foreach ($item in $results) * $item #end {{/velocity}}
While I get a result it is an unexpected value, it appears to have returned the object ID see below:
* [Ljava.lang.Object;@af0baa
That's normal because $item is an array of Java objects (xobject name and property value) and by simply printing $item you are in fact calling its toString() method which returns the string you see.
It should be noted when I just try to get the obj.name without the property value it works fine.
That's normal too, because in this case $item is not an array of Java objects but a string (xobject name). You can use this code to display the results: |=Object Name|=Property Value #foreach ($item in $results) |$item.get(0)|$item.get(1) #end Hope this helps, Marius
Now that I know the Query generally works in Velocity, It should be the same thing to just cut and paste the Query into the DB List attribute of an object.
Thanks for your continued help and timely response.
On a side note, I would like to be able to create links on results (when used inside of a velocity script on a page), is there an easy way to do that as well?
Martin Modus Operandi