[xwiki-users] Is there a way to dynamically change the values on a static list or on any other property of a xwiki class?
Hi everybody, Is there a way to dynamically (through groovy code) change the values on a static list or on any other property of a xwiki class? I am using *field = document.getxWikiClass().get("propertyName")* to get the property. document is of type* com.xpn.xwiki.api.Document*. But when I try to change the value using * field.getPropertyClass().setValues("val1|val2|val3")* I get a *null* value from* field.getPropertyClass()* I am following the information on http://www.mail-archive.com/[email protected]/msg10692.html I am using groovy on xwiki 2.0.2.24645 Regards Abel
I can tell you that it can be done, anything which can be done by the user can be done with groovy. document.getxWikiClass().get("propertyName") returns an object of type element. http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi... I think you need to drop out of the api section into the core (which requires programming rights but so does groovy) document.getDocument().getxWikiClass() gives you an object of type BaseClass which I think is what you are after. http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi... Caleb Abel Solórzano Astorga wrote:
Hi everybody,
Is there a way to dynamically (through groovy code) change the values on a static list or on any other property of a xwiki class?
I am using *field = document.getxWikiClass().get("propertyName")* to get the property.
document is of type* com.xpn.xwiki.api.Document*.
But when I try to change the value using * field.getPropertyClass().setValues("val1|val2|val3")* I get a *null* value from* field.getPropertyClass()*
I am following the information on http://www.mail-archive.com/[email protected]/msg10692.html
I am using groovy on xwiki 2.0.2.24645
Regards
Abel _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Thanks Caleb, I follow your recommendation, but I am getting a BaseClass with no properties. The class I am creating it is supposed to have 4 properties. I am using the folling code to use the class: *...* *docname = xwiki.getUniquePageName("ValidationSample", "TestClass") valdoc = xwiki.getDocument("ValidationSample." + docname) ok = valdoc.newObject("ValidationSample.TestClass") ok = valdoc.updateObjectFromRequest("ValidationSample.TestClass")* * ... valdoc.use("ValidationSample.TestClass")* ValidationSample.TestClass has 4 properties (2 TextAreas and 2 a Static Lists). Then to get the property that I need to dynamically change: *field = valdoc.getDocument().getxWikiClass().get("Project")* But I get a null value from * valdoc.getDocument().getxWikiClass().get("Project")*. The BaseClass returned by *valdoc.getDocument().getxWikiClass() *is a *ValidationSample.TestClass *class but the Properties collection is empty. Regards, Abel On Wed, Mar 3, 2010 at 1:04 AM, Caleb James DeLisle < [email protected]> wrote:
I can tell you that it can be done, anything which can be done by the user can be done with groovy.
document.getxWikiClass().get("propertyName") returns an object of type element.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
I think you need to drop out of the api section into the core (which requires programming rights but so does groovy) document.getDocument().getxWikiClass() gives you an object of type BaseClass which I think is what you are after.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
Caleb
Abel Solórzano Astorga wrote:
Hi everybody,
Is there a way to dynamically (through groovy code) change the values on a static list or on any other property of a xwiki class?
I am using *field = document.getxWikiClass().get("propertyName")* to get the property.
document is of type* com.xpn.xwiki.api.Document*.
But when I try to change the value using * field.getPropertyClass().setValues("val1|val2|val3")* I get a *null* value from* field.getPropertyClass()*
I am following the information on http://www.mail-archive.com/[email protected]/msg10692.html
I am using groovy on xwiki 2.0.2.24645
Regards
Abel _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Abel Solórzano Astorga wrote:
Thanks Caleb,
I follow your recommendation, but I am getting a BaseClass with no properties. The class I am creating it is supposed to have 4 properties.
I am using the folling code to use the class:
*...*
*docname = xwiki.getUniquePageName("ValidationSample", "TestClass") valdoc = xwiki.getDocument("ValidationSample." + docname) ok = valdoc.newObject("ValidationSample.TestClass") ok = valdoc.updateObjectFromRequest("ValidationSample.TestClass")* * ...
valdoc.use("ValidationSample.TestClass")*
ValidationSample.TestClass has 4 properties (2 TextAreas and 2 a Static Lists).
Then to get the property that I need to dynamically change:
*field = valdoc.getDocument().getxWikiClass().get("Project")*
But I get a null value from * valdoc.getDocument().getxWikiClass().get("Project")*. The BaseClass returned "get" calls getField().getValue() maybe the problem is that BaseCollection is used for objects and xclasses and get is only useful for objects. Try getField()
by *valdoc.getDocument().getxWikiClass() *is a *ValidationSample.TestClass *class but the Properties collection is empty.
Because of a bug in groovy you can view private fields so you can look directly at the fields in the class with for(String name : valdoc.getDocument().getxWikiClass().fields.keySet()) { println(name); } Also if you want to change the prettyName of a class property (for example), you would have to cast the field to PropertyClass (didn't test this but it should work.) ((PropertyClass) valdoc.getDocument().getxWikiClass().getField()).setPrettyName("new name"); Caleb
Regards,
Abel
On Wed, Mar 3, 2010 at 1:04 AM, Caleb James DeLisle < [email protected]> wrote:
I can tell you that it can be done, anything which can be done by the user can be done with groovy.
document.getxWikiClass().get("propertyName") returns an object of type element.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
I think you need to drop out of the api section into the core (which requires programming rights but so does groovy) document.getDocument().getxWikiClass() gives you an object of type BaseClass which I think is what you are after.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
Caleb
Abel Solórzano Astorga wrote:
Hi everybody,
Is there a way to dynamically (through groovy code) change the values on a static list or on any other property of a xwiki class?
I am using *field = document.getxWikiClass().get("propertyName")* to get the property.
document is of type* com.xpn.xwiki.api.Document*.
But when I try to change the value using * field.getPropertyClass().setValues("val1|val2|val3")* I get a *null* value from* field.getPropertyClass()*
I am following the information on http://www.mail-archive.com/[email protected]/msg10692.html
I am using groovy on xwiki 2.0.2.24645
Regards
Abel _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Thanks again Caleb, I try your suggestion, but I keep getting a null value from * valdoc.getDocument().**getxWikiClass().get("Project")*. The fields Map ( *valdoc.getDocument().**getxWikiClass().fields.keySet(**)*) is empty. I put the following line on the code: *println valdoc.getDocument().getxWikiClass().toString()* and the result is *<class> <name>ValidationSample.TestClass_6</name> <customClass></customClass> <customMapping></customMapping> <defaultViewSheet></defaultViewSheet> <defaultEditSheet></defaultEditSheet> <defaultWeb></defaultWeb> <nameField></nameField> <validationScript></validationScript> </class>* I was expecting to see the properties on the XML. Abel On Fri, Mar 5, 2010 at 1:45 AM, Caleb James DeLisle < [email protected]> wrote:
Abel Solórzano Astorga wrote:
Thanks Caleb,
I follow your recommendation, but I am getting a BaseClass with no properties. The class I am creating it is supposed to have 4 properties.
I am using the folling code to use the class:
*...*
*docname = xwiki.getUniquePageName("ValidationSample", "TestClass") valdoc = xwiki.getDocument("ValidationSample." + docname) ok = valdoc.newObject("ValidationSample.TestClass") ok = valdoc.updateObjectFromRequest("ValidationSample.TestClass")* * ...
valdoc.use("ValidationSample.TestClass")*
ValidationSample.TestClass has 4 properties (2 TextAreas and 2 a Static Lists).
Then to get the property that I need to dynamically change:
*field = valdoc.getDocument().getxWikiClass().get("Project")*
But I get a null value from * valdoc.getDocument().getxWikiClass().get("Project")*. The BaseClass returned "get" calls getField().getValue() maybe the problem is that BaseCollection is used for objects and xclasses and get is only useful for objects. Try getField()
by *valdoc.getDocument().getxWikiClass() *is a *ValidationSample.TestClass *class but the Properties collection is empty.
Because of a bug in groovy you can view private fields so you can look directly at the fields in the class with
for(String name : valdoc.getDocument().getxWikiClass().fields.keySet()) { println(name); }
Also if you want to change the prettyName of a class property (for example), you would have to cast the field to PropertyClass (didn't test this but it should work.)
((PropertyClass) valdoc.getDocument().getxWikiClass().getField()).setPrettyName("new name");
Caleb
Regards,
Abel
On Wed, Mar 3, 2010 at 1:04 AM, Caleb James DeLisle < [email protected]> wrote:
I can tell you that it can be done, anything which can be done by the user can be done with groovy.
document.getxWikiClass().get("propertyName") returns an object of type element.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
I think you need to drop out of the api section into the core (which requires programming rights but so does groovy) document.getDocument().getxWikiClass() gives you an object of type BaseClass which I think is what you are after.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
Caleb
Abel Solórzano Astorga wrote:
Hi everybody,
Is there a way to dynamically (through groovy code) change the values
on
a
static list or on any other property of a xwiki class?
I am using *field = document.getxWikiClass().get("propertyName")* to get the property.
document is of type* com.xpn.xwiki.api.Document*.
But when I try to change the value using * field.getPropertyClass().setValues("val1|val2|val3")* I get a *null* value from* field.getPropertyClass()*
I am following the information on http://www.mail-archive.com/[email protected]/msg10692.html
I am using groovy on xwiki 2.0.2.24645
Regards
Abel _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
It looks like you have isolated the problem because doing the same thing with a class that is known to exist $xwiki.getDocument('XWiki.XWikiPreferences').getDocument().getxWikiClass().toString() displays all of the properties in xml format. I also double checked by adding a property to Main.WebHome class and viewing that, it works as expected. I recommend you double check valdoc, and add if (valdoc.isNew()) { println("oops I didn't load the document."); } to your script. Caleb Abel Solórzano Astorga wrote:
Thanks again Caleb,
I try your suggestion, but I keep getting a null value from * valdoc.getDocument().**getxWikiClass().get("Project")*.
The fields Map ( *valdoc.getDocument().**getxWikiClass().fields.keySet(**)*) is empty.
I put the following line on the code:
*println valdoc.getDocument().getxWikiClass().toString()*
and the result is
*<class> <name>ValidationSample.TestClass_6</name> <customClass></customClass> <customMapping></customMapping> <defaultViewSheet></defaultViewSheet> <defaultEditSheet></defaultEditSheet> <defaultWeb></defaultWeb> <nameField></nameField> <validationScript></validationScript> </class>*
I was expecting to see the properties on the XML.
Abel
On Fri, Mar 5, 2010 at 1:45 AM, Caleb James DeLisle < [email protected]> wrote:
Abel Solórzano Astorga wrote:
Thanks Caleb,
I follow your recommendation, but I am getting a BaseClass with no properties. The class I am creating it is supposed to have 4 properties.
I am using the folling code to use the class:
*...*
*docname = xwiki.getUniquePageName("ValidationSample", "TestClass") valdoc = xwiki.getDocument("ValidationSample." + docname) ok = valdoc.newObject("ValidationSample.TestClass") ok = valdoc.updateObjectFromRequest("ValidationSample.TestClass")* * ...
valdoc.use("ValidationSample.TestClass")*
ValidationSample.TestClass has 4 properties (2 TextAreas and 2 a Static Lists).
Then to get the property that I need to dynamically change:
*field = valdoc.getDocument().getxWikiClass().get("Project")*
But I get a null value from * valdoc.getDocument().getxWikiClass().get("Project")*. The BaseClass returned "get" calls getField().getValue() maybe the problem is that BaseCollection is used for objects and xclasses and get is only useful for objects. Try getField()
by *valdoc.getDocument().getxWikiClass() *is a *ValidationSample.TestClass *class but the Properties collection is empty. Because of a bug in groovy you can view private fields so you can look directly at the fields in the class with
for(String name : valdoc.getDocument().getxWikiClass().fields.keySet()) { println(name); }
Also if you want to change the prettyName of a class property (for example), you would have to cast the field to PropertyClass (didn't test this but it should work.)
((PropertyClass) valdoc.getDocument().getxWikiClass().getField()).setPrettyName("new name");
Caleb
Regards,
Abel
On Wed, Mar 3, 2010 at 1:04 AM, Caleb James DeLisle < [email protected]> wrote:
I can tell you that it can be done, anything which can be done by the user can be done with groovy.
document.getxWikiClass().get("propertyName") returns an object of type element.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
I think you need to drop out of the api section into the core (which requires programming rights but so does groovy) document.getDocument().getxWikiClass() gives you an object of type BaseClass which I think is what you are after.
http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwi...
Caleb
Abel Solórzano Astorga wrote:
Hi everybody,
Is there a way to dynamically (through groovy code) change the values
on
a
static list or on any other property of a xwiki class?
I am using *field = document.getxWikiClass().get("propertyName")* to get the property.
document is of type* com.xpn.xwiki.api.Document*.
But when I try to change the value using * field.getPropertyClass().setValues("val1|val2|val3")* I get a *null* value from* field.getPropertyClass()*
I am following the information on http://www.mail-archive.com/[email protected]/msg10692.html
I am using groovy on xwiki 2.0.2.24645
Regards
Abel _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On 03/06/2010 01:06 AM, Abel Solórzano Astorga wrote:
Thanks again Caleb,
I try your suggestion, but I keep getting a null value from * valdoc.getDocument().**getxWikiClass().get("Project")*.
The fields Map ( *valdoc.getDocument().**getxWikiClass().fields.keySet(**)*) is empty.
I put the following line on the code:
*println valdoc.getDocument().getxWikiClass().toString()*
and the result is
*<class> <name>ValidationSample.TestClass_6</name> <customClass></customClass> <customMapping></customMapping> <defaultViewSheet></defaultViewSheet> <defaultEditSheet></defaultEditSheet> <defaultWeb></defaultWeb> <nameField></nameField> <validationScript></validationScript> </class>*
I was expecting to see the properties on the XML.
Abel
Is valdoc the document containing the class? It doesn't look like it from the name. So, you must do something like:
{{velocity}} #set($classDoc = $xwiki.getDocument('Your.Class')) #set($propertyDefinition = $classDoc.getxWikiClass().get('project')) ## $propertyDefinition.class should now print com.xpn.xwiki.api.PropertyClass ## Unfortunately, at this point you need programming rights to go into the inner, protected property definition #set($propertyDefinition = $propertyDefinition.getPropertyClass()) ## $propertyDefinition.class should now print com.xpn.xwiki.objects.classes.StaticListClass ## If it doesn't, then you don't have programming rights. $propertyDefinition.setValues('a|b|c') ## Don't forget to save $classDoc.save() {{/velocity}}
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Thanks a lot guys, I followed the suggestion of Sergiu and it works just fine. Abel On Fri, Mar 5, 2010 at 6:51 PM, Sergiu Dumitriu <[email protected]> wrote:
On 03/06/2010 01:06 AM, Abel Solórzano Astorga wrote:
Thanks again Caleb,
I try your suggestion, but I keep getting a null value from * valdoc.getDocument().**getxWikiClass().get("Project")*.
The fields Map ( *valdoc.getDocument().**getxWikiClass().fields.keySet(**)*) is empty.
I put the following line on the code:
*println valdoc.getDocument().getxWikiClass().toString()*
and the result is
*<class> <name>ValidationSample.TestClass_6</name> <customClass></customClass> <customMapping></customMapping> <defaultViewSheet></defaultViewSheet> <defaultEditSheet></defaultEditSheet> <defaultWeb></defaultWeb> <nameField></nameField> <validationScript></validationScript> </class>*
I was expecting to see the properties on the XML.
Abel
Is valdoc the document containing the class? It doesn't look like it from the name.
So, you must do something like:
{{velocity}} #set($classDoc = $xwiki.getDocument('Your.Class')) #set($propertyDefinition = $classDoc.getxWikiClass().get('project')) ## $propertyDefinition.class should now print com.xpn.xwiki.api.PropertyClass ## Unfortunately, at this point you need programming rights to go into the inner, protected property definition #set($propertyDefinition = $propertyDefinition.getPropertyClass()) ## $propertyDefinition.class should now print com.xpn.xwiki.objects.classes.StaticListClass ## If it doesn't, then you don't have programming rights. $propertyDefinition.setValues('a|b|c') ## Don't forget to save $classDoc.save() {{/velocity}}
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
Abel Solórzano Astorga -
Caleb James DeLisle -
Sergiu Dumitriu