Marius Dumitru Florea wrote:
> 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
>>     
You can use the public API method $searchDocuments this way...

{{velocity}}
#set($query = ", BaseObject as obj, StringProperty as productName where 
doc.fullName = obj.name and obj.className='CustClasses.ToolClass' order 
by doc.fullName asc")

#set($results=$xwiki.searchDocuments($query))
#foreach($item in $results)
        #set($itemdoc = $xwiki.getDocument($item))
                [[$itemdoc.display('Name')>>$item]]
#end
{{/velocity}}

Look for $searchDocuments in the API JavaDoc to better understantd what 
you are doing...

http://platform.xwiki.org/xwiki/bin/view/DevGuide/API

I, like you, I'm still trying to understand the whole stuff and to be 
able to do things as "easy" as developers do! :-)

Greetings,

Ricardo

-- 
Ricardo Rodríguez
CTO
eBioTIC.
Life Sciences, Data Modeling and Information Management Systems

_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to