Jerome Velociter wrote:
Hi,
See below:
BrianJones wrote:
Hi all,
I'm having trouble using Velocity to analyze the boolean value of a property
of a class.
For example, I have class X, with a property Y (I'll call this property
'example_bool' in the lower example code) which is of type 'Boolean'.
I've
configured this property to use radio buttons so the user is only able to
choose one value. I've created several objects of this class, making sure
to utilize both the 'Yes' and 'No' values for some of these objects (to
ensure for testing purposes I have some of both).
This class also has another property, a static list, of location strings,
such as 'Location X', 'Location Y', etc.
Now, on a page, I am trying to calculate how many of each location have the
boolean value of Yes and no with the following velocity/HQL statement:
#set ($results = $xwiki.search("select obj.name from BaseObject obj,
StringProperty prop where obj.className='Example.ExampleClass' and
obj.name<>'Example.ExampleClassTemplate' and prop.id.id=obj.id and
prop.name='location' and prop.value='Location X' order by obj.name
asc"))
#set ($numTrue = 0)
#set ($numFalse = 0)
#foreach ($item in $results)
#set ($object = $xwiki.getDocument(${item}))
#if (!$object.get("example_bool"))
#set ($numFalse = $numFalse + 1)
#else
#set ($numTrue = $numTrue + 1)
#end
#end
Try to replace
#if (!$object.get("example_bool"))
by
#if (!$object.getProperty("example_bool").value)
#if (!$object.getProperty("example_bool").value == 1)
The property value is an integer, not a boolean.
Hope this helps (haven't tested, I admit)
Jerome.
This code is being executed without error,
however, the 'True' count is
always being evaluated as the total number of objects, while the 'False'
count always stays at 0, even though I KNOW there are objects in this group
that have the value of 'No' for the 'example_bool' property.
Does anyone know what I'm doing wrong, or have any ideas that might help me
out? Thanks in advance gang.
On a side note, I've also noted that when using the Boolean property, the
user has the choice of 'Yes', 'No' and '---'. What is this later
value
('---') and why is it always included? To me, the meaning of Boolean means
'True OR False' and nothing else. Does this third value have a purpose?
And is there a way of excluding it from the choices the user sees?
Thanks again everyone!
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Sergiu Dumitriu
http://purl.org/net/sergiu/