On 09/07/2011 10:52 AM, Karel Gardas wrote:
>
> Hi Sergiu,
>
> thanks a lot for your help and answer. The problem which I see now is
> that I'm able to get all the selected values into one line printed out
> from the $doc.display($prop.getName()), but I'm not able to get the
> values with your recommended way. Anyway, concrete comments are below, I
> described there what I did exactly.
>
> On 09/ 2/11 04:59 AM, Sergiu Dumitriu wrote:
>> Yes, this is supported and it's something quite fundamental, so it
>> should work very well.
>
> That's indeed good to know. For reference platform I've installed
> xwiki-enterprise-jetty-hsqldb-3.1. All the attempts described below were
> done on this platform.
>
>> Open the class editor and add a new property of type Database List.
>>
>> Write the query you want to use to extract the possible values for that
>> property from the database.
>
> I did and I used this query:
>
> select doc.name, doc.date from XWikiDocument doc
>
> I selected Multiple Select and also Rational Storage. I also defined
> Multiselect and Join separators to `,'. Size of the corresponding form
> element in edit mode is set to `1'. The element itself does have its
> name and pretty name set to `list'. The query here is just as simple as
> possible example I'm using to get at least something out from the XWiki
> and verify that this functionality is working...
>
>> Make sure you select the Multiple Select and Relational Storage
>> checkboxes. Multiple Select allows you to select and store multiple
>> values from the list, while Relational Storage makes it easier to
>> integrate that property into other queries by storing each selected item
>> in its own entry in the database (without it all the selected values are
>> stored in one row, concatenated into a VARCHAR column), and to store
>> more than a few selected values (since the column allows at most 255
>> characters in total).
>>
>> Change the Display Type select to what you want. Checkbox is one of the
>> possible values. If you leave it to Select, also increase the value of
>> the "Size of the corresponding form element in edit mode" option.
>>
>
> OK, I've used checkbox now.
>
>> Now, when you display the field in edit mode it should appear as a list
>> of checkboxes.
>>
>> To get the selected values, you mustn't use the display() or get()
>> methods, since those are for generating HTML, and not for accessing the
>> raw value of the property. Use something like this:
>>
>> $doc.getObject('Your.Class').getProperty('propertyName').values
>>
>> This should return an ArrayList with all the selected values.
>
> OK, this is a little bit confusing to me so I'll describe what I did
> exactly. After class definition I've made class's sheet and template.
> Template code is what xwiki generates by default. sheet code is changed
> by me to (full code listing):
>
> {{velocity}}
> #set($class = $doc.getObject('Test.UserPageCounterClass').xWikiClass)
> #foreach($prop in $class.properties)
> ; $prop.prettyName
> : $doc.display($prop.getName())
> #end
> #set($values =
> $doc.getObject('Test.UserPageCounterClass').getProperty('list').values)
> $values
> #foreach($i in $values)
> ; $i
> #end
> {{/velocity}}
>
> I've also added template provider to enable the template usage.
>
> And finally, when I try to create the page from this template I see the
> list of dates like:
>
> 2009-09-16 15:32:49.0
> 2009-09-16 15:32:49.0
> 2009-09-16 15:32:49.0
> 2009-09-16 15:32:49.0
> 2008-11-26 07:44:45.0
> 2008-08-27 20:00:06.0
> 2008-11-16 07:45:29.0
>
> I don't see any page name and such so I guess my select query above is
> wrong or at least `doc.name' is not defined column in the table.
When selecting two columns, the first one is considered the key stored
in the database and the second one is the pretty name displayed to
users. So if you inspect the generated HTML, you'll see that the inputs
have as value the document name, and as visible text label the document
modification date.
> And now I select few dates from this and hit Save&View button. What I
> see as a resulting page is this:
>
> list
> 2009-09-16 15:32:49.0, 2009-09-16 15:32:49.0, 2009-09-16 15:32:49.0,
> 2009-09-16 15:32:49.0, 2008-11-26 07:44:45.0
> $values
>
> from this it looks like my foreach ($i in $values) iteraction is not
> working since it does not show any value. What's printing dates is
> $doc.display($prop.getName()) call.
Ah, my mistake, it should be
$doc.getObject('Test.UserPageCounterClass').getProperty('list').value
with no s at the end, value instead of values. No idea how that got there...
> This is kind of confusing to me, but I'm really not sure if I did any
> mistake along the way on this. Do you see anything suspicious on my
> description?
>
> Thanks a lot!
> Karel
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs