Re: [xwiki-users] Trouble assessing boolean property value of an object
Sergiu, Thanks for all your help, everything is working perfectly now! Sergiu Dumitriu-2 wrote: Yes, I read the whole snippet again. The problem is that $object is not an object, but a document. You must replace: #set ($object = $xwiki.getDocument(${item})) with #set($object = $xwiki.getDocument(${item}).getObject('Example.ExampleClass')) -- View this message in context: http://n2.nabble.com/Trouble-assessing-boolean-property-value-of-an-object-tp1450033p1455136.html Sent from the XWiki- Users mailing list archive at Nabble.com. ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Trouble assessing boolean property value of an object
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) 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@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Trouble assessing boolean property value of an object
Jerome, Thanks for your suggestion, but it didn't seem to work... Jerome Velociter-2 wrote: Try to replace #if (!$object.get(example_bool)) by #if (!$object.getProperty(example_bool).value) Hope this helps (haven't tested, I admit) Jerome. I tried using: #if (!$object.get(example_bool).value) #if (!$object.getProperty(example_bool)) #if (!$object.getProperty(example_bool).value) All of these variations produce similar results, but not exactly the same as the original method I tried. The only difference now is that all are being equated to 'False' and none are 'True' (the exact opposite of the behavior when using #if (!$object.get(example_bool))). Still not the correct output. Any other ideas? -- View this message in context: http://n2.nabble.com/Trouble-assessing-boolean-property-value-of-an-object-tp1450033p1450689.html Sent from the XWiki- Users mailing list archive at Nabble.com. ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
Re: [xwiki-users] Trouble assessing boolean property value of an object
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@xwiki.org http://lists.xwiki.org/mailman/listinfo/users -- Sergiu Dumitriu http://purl.org/net/sergiu/ ___ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users