[xwiki-users] Class with hibernate query
Hi (XWiki 2.7.2) I've defined a class with a property defined as DatabaseList It's a multi select The Hibernate query is: select ata.filename from XWikiAttachment as ata, XWikiDocument as doc where doc.fullName ='CdLSAssociations.FlagAttachments' and doc.id = ata.docId order by ata.filename This works fine, when I create a new object of this class I can select multiple fileNames My questions; I would like to strip the filename extension from the ata.filename (ar.png => ar) I was trying a substr(ata.filename,1,2) does not work How do I do this? Second, I wonder if it is possible to add a second collumn to the query that uses a translation table like select ata.filename, $msg.get(ata.filename) as translatedName from XWikiAttachment as ata, XWikiDocument as doc where doc.fullName ='CdLSAssociations.FlagAttachments' and doc.id = ata.docId order by translatedName and use in the class property defenition the ID Field name and Value Field Name Any help is highly appreciated Gerritjan
On 06/12/2011 05:39 PM, Gerritjan Koekkoek wrote:
Hi
(XWiki 2.7.2) I've defined a class with a property defined as DatabaseList It's a multi select The Hibernate query is:
select ata.filename from XWikiAttachment as ata, XWikiDocument as doc where doc.fullName ='CdLSAssociations.FlagAttachments' and doc.id = ata.docId order by ata.filename
This works fine, when I create a new object of this class I can select multiple fileNames
My questions; I would like to strip the filename extension from the ata.filename (ar.png => ar) I was trying a substr(ata.filename,1,2) does not work How do I do this?
In theory you could use something like this: select ata.filename, substring(ata.filename, 0, locate(ata.filename, '.')) from XWikiAttachment... But only in theory. There's a bug in the DBList query processor that breaks that.
Second, I wonder if it is possible to add a second collumn to the query that uses a translation table like select ata.filename, $msg.get(ata.filename) as translatedName
This can't work. There are two languages involved here, Velocity and HQL, and they don't mix in real time.
from XWikiAttachment as ata, XWikiDocument as doc where doc.fullName ='CdLSAssociations.FlagAttachments' and doc.id = ata.docId order by translatedName
and use in the class property defenition the ID Field name and Value Field Name
Any help is highly appreciated
I'd recommend that you write a custom displayer for this field, instead of relying on the default display. You should use the first, simple query that just retrieves the attachment names, then create you own display that substrings the extension for the displayed option label. -- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (2)
-
Gerritjan Koekkoek -
Sergiu Dumitriu