DBStringList property and checkbox functionality example.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

DBStringList property and checkbox functionality example.

kgardas
Hello,

is there any example which shows usage of DBStringList property together
with support for selecting multiple values of this property (by for
example using checkboxes) and also showing how such values are later
obtained from the property?

I'm asking since I'm not sure if property is able to kind of change into
property list (probably) and also I'm fighting with this and I'm still
not able to obtain more than one value from returned property object.

Thanks!
Karel
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: DBStringList property and checkbox functionality example.

Sergiu Dumitriu-2
On 08/31/2011 10:50 AM, Karel Gardas wrote:

> Hello,
>
> is there any example which shows usage of DBStringList property together
> with support for selecting multiple values of this property (by for
> example using checkboxes) and also showing how such values are later
> obtained from the property?
>
> I'm asking since I'm not sure if property is able to kind of change into
> property list (probably) and also I'm fighting with this and I'm still
> not able to obtain more than one value from returned property object.

Hi Karel,

Yes, this is supported and it's something quite fundamental, so it
should work very well.

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.

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.

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.

--
Sergiu Dumitriu
http://purl.org/net/sergiu/
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: DBStringList property and checkbox functionality example.

kgardas

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.

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.

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
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: DBStringList property and checkbox functionality example.

Sergiu Dumitriu-2
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
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: DBStringList property and checkbox functionality example.

kgardas

Sergiu,

On 09/ 7/11 05:04 PM, Sergiu Dumitriu wrote:

>> 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.

This is indeed interesting and good to know!

>> 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...

Great! So this fixed that issue and now I'm able to multi-select not
only from DBStringList but from also our own (hopefully soon to be
contributed) SPARQ query property.

Thanks a lot for your help with this!
Karel
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs