[xwiki-devs] strange behaviour when modifying an DBStringList prop in an object from a velocity script
hello guys, I do the following: - I have a class with a DBStringList property "mylist" - In a velocity script, I do: #set($obj = $doc.getObject("MyClass", $mynb) #set($mylist = $obj.get("mylist")) #set($mylist = "${mylist}|${mynewlistitem}") #set($ret = $obj.set("mylist", $mylist)) #set($ret = $doc.save()) - I run this script and I can see in the DB that "mynewlistitem" was added as listitem to "mylist" but the item doesn't appear in the object editor for property "mylist" in my document. - Moreover, I get some rendering exception in contentview.vm when I try to access this object in other velocity scripts. - When I create the link using the Object editor, then everything works well but I don't see anything different in the DB from the previous state. - I have tried the same with: #set($obj = $doc.getObject("MyClass", $mynb) #set($mylist = $obj.getProperty("mylist").getValue()) #set($ret = $mylist.add("${mynewlistitem}")) #set($ret = $doc.save()) same result... It seems the Object property is saved but it is not taken into account by the object in the document. Do you any clue for me? regards Pascal
Pascal Voitot wrote:
hello guys, I do the following: - I have a class with a DBStringList property "mylist" - In a velocity script, I do: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.get("mylist")) #set($mylist = "${mylist}|${mynewlistitem}") #set($ret = $obj.set("mylist", $mylist))
#set($ret = $doc.save())
- I run this script and I can see in the DB that "mynewlistitem" was added as listitem to "mylist" but the item doesn't appear in the object editor for property "mylist" in my document. - Moreover, I get some rendering exception in contentview.vm when I try to access this object in other velocity scripts. - When I create the link using the Object editor, then everything works well but I don't see anything different in the DB from the previous state.
- I have tried the same with: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.getProperty("mylist").getValue()) #set($ret = $mylist.add("${mynewlistitem}"))
#set($ret = $doc.save())
same result...
It seems the Object property is saved but it is not taken into account by the object in the document.
Do you any clue for me?
- is the property multiselect? relational storage? - would the mynewlistitem value be returned by the DB search? Or is it a new value you want to include manually? - does the DB query normally return one or two values? - what exactly is the error you receive? -- Sergiu Dumitriu http://purl.org/net/sergiu/
plz see below thks Pascal On Thu, Oct 2, 2008 at 6:01 PM, Sergiu Dumitriu <[email protected]> wrote:
Pascal Voitot wrote:
hello guys, I do the following: - I have a class with a DBStringList property "mylist" - In a velocity script, I do: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.get("mylist")) #set($mylist = "${mylist}|${mynewlistitem}") #set($ret = $obj.set("mylist", $mylist))
#set($ret = $doc.save())
- I run this script and I can see in the DB that "mynewlistitem" was added as listitem to "mylist" but the item doesn't appear in the object editor for property "mylist" in my document. - Moreover, I get some rendering exception in contentview.vm when I try to access this object in other velocity scripts. - When I create the link using the Object editor, then everything works well but I don't see anything different in the DB from the previous state.
- I have tried the same with: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.getProperty("mylist").getValue()) #set($ret = $mylist.add("${mynewlistitem}"))
#set($ret = $doc.save())
same result...
It seems the Object property is saved but it is not taken into account by the object in the document.
Do you any clue for me?
- is the property multiselect? relational storage?
multiselect relation storage
- would the mynewlistitem value be returned by the DB search? Or is it a new value you want to include manually?
in Object editor, I use the DB search to return this value (which is stored in DB) plus another string (which is the displayed value) select myvalue, mystring from ... In my velocity script, I had this value manually directly accessing the property... But after that, I verify it has been stored using the Object editor...
- does the DB query normally return one or two values?
2 values
- what exactly is the error you receive?
I don't have it here now but this is a kind of StackOverflow in getRenderedContent() I will search with the debugger if you don't have any quick idea... In fact, as my property is well stored in the DB (I have verified manually), I don't see the wrong interaction between this property and its object in this case... what's different between accessing the property from the object editor or from my velocity script?
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
OK, I don't have solved everything but I have found the origin of the stackoverflow... I coded a Recursive VelocityMacro and apparently variables inside VM macro are not local and it makes my recursion infinite!!! Apparently, there is an option in velocity to make local macro variables have only a local scope. Do you see any problem about this? I have modified my dbstringlist SQL query to use only one column to be sure this is the easiest case... I then add a listitem manually to the list property of the object in my velocity script. Everything is OK but sometimes the list item appears in the object editor, sometimes not and i don't understand why yet! Still investigating! best regards PAscal On Thu, Oct 2, 2008 at 6:22 PM, Pascal Voitot <[email protected]>wrote:
plz see below
thks Pascal
On Thu, Oct 2, 2008 at 6:01 PM, Sergiu Dumitriu <[email protected]> wrote:
Pascal Voitot wrote:
hello guys, I do the following: - I have a class with a DBStringList property "mylist" - In a velocity script, I do: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.get("mylist")) #set($mylist = "${mylist}|${mynewlistitem}") #set($ret = $obj.set("mylist", $mylist))
#set($ret = $doc.save())
- I run this script and I can see in the DB that "mynewlistitem" was added as listitem to "mylist" but the item doesn't appear in the object editor for property "mylist" in my document. - Moreover, I get some rendering exception in contentview.vm when I try to access this object in other velocity scripts. - When I create the link using the Object editor, then everything works well but I don't see anything different in the DB from the previous state.
- I have tried the same with: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.getProperty("mylist").getValue()) #set($ret = $mylist.add("${mynewlistitem}"))
#set($ret = $doc.save())
same result...
It seems the Object property is saved but it is not taken into account by the object in the document.
Do you any clue for me?
- is the property multiselect? relational storage?
multiselect relation storage
- would the mynewlistitem value be returned by the DB search? Or is it a new value you want to include manually?
in Object editor, I use the DB search to return this value (which is stored in DB) plus another string (which is the displayed value)
select myvalue, mystring from ...
In my velocity script, I had this value manually directly accessing the property... But after that, I verify it has been stored using the Object editor...
- does the DB query normally return one or two values?
2 values
- what exactly is the error you receive?
I don't have it here now but this is a kind of StackOverflow in getRenderedContent()
I will search with the debugger if you don't have any quick idea... In fact, as my property is well stored in the DB (I have verified manually), I don't see the wrong interaction between this property and its object in this case... what's different between accessing the property from the object editor or from my velocity script?
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Pascal Voitot wrote:
OK, I don't have solved everything but I have found the origin of the stackoverflow... I coded a Recursive VelocityMacro and apparently variables inside VM macro are not local and it makes my recursion infinite!!! Apparently, there is an option in velocity to make local macro variables have only a local scope. Do you see any problem about this?
Yes, I had my share of pain with the fact that variables defined inside macros are global... I am +1 for making them local, but all the macros should be checked, since some of them might use this "feature".
I have modified my dbstringlist SQL query to use only one column to be sure this is the easiest case... I then add a listitem manually to the list property of the object in my velocity script. Everything is OK but sometimes the list item appears in the object editor, sometimes not and i don't understand why yet!
It should always be there. The code says that if the selected item is not in the list obtained from the DB, then it is manually added at the end.
Still investigating!
best regards PAscal
On Thu, Oct 2, 2008 at 6:22 PM, Pascal Voitot <[email protected]>wrote:
plz see below
thks Pascal
On Thu, Oct 2, 2008 at 6:01 PM, Sergiu Dumitriu <[email protected]> wrote:
Pascal Voitot wrote:
hello guys, I do the following: - I have a class with a DBStringList property "mylist" - In a velocity script, I do: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.get("mylist")) #set($mylist = "${mylist}|${mynewlistitem}") #set($ret = $obj.set("mylist", $mylist))
#set($ret = $doc.save())
- I run this script and I can see in the DB that "mynewlistitem" was added as listitem to "mylist" but the item doesn't appear in the object editor for property "mylist" in my document. - Moreover, I get some rendering exception in contentview.vm when I try to access this object in other velocity scripts. - When I create the link using the Object editor, then everything works well but I don't see anything different in the DB from the previous state.
- I have tried the same with: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.getProperty("mylist").getValue()) #set($ret = $mylist.add("${mynewlistitem}"))
#set($ret = $doc.save())
same result...
It seems the Object property is saved but it is not taken into account by the object in the document.
Do you any clue for me?
- is the property multiselect? relational storage?
multiselect relation storage
- would the mynewlistitem value be returned by the DB search? Or is it a new value you want to include manually?
in Object editor, I use the DB search to return this value (which is stored in DB) plus another string (which is the displayed value)
select myvalue, mystring from ...
In my velocity script, I had this value manually directly accessing the property... But after that, I verify it has been stored using the Object editor...
- does the DB query normally return one or two values?
2 values
- what exactly is the error you receive?
I don't have it here now but this is a kind of StackOverflow in getRenderedContent()
I will search with the debugger if you don't have any quick idea... In fact, as my property is well stored in the DB (I have verified manually), I don't see the wrong interaction between this property and its object in this case... what's different between accessing the property from the object editor or from my velocity script?
-- Sergiu Dumitriu http://purl.org/net/sergiu/
On Oct 3, 2008, at 12:18 PM, Sergiu Dumitriu wrote:
Pascal Voitot wrote:
OK, I don't have solved everything but I have found the origin of the stackoverflow... I coded a Recursive VelocityMacro and apparently variables inside VM macro are not local and it makes my recursion infinite!!! Apparently, there is an option in velocity to make local macro variables have only a local scope. Do you see any problem about this?
Yes, I had my share of pain with the fact that variables defined inside macros are global... I am +1 for making them local, but all the macros should be checked, since some of them might use this "feature".
Velocity Macros *are* local (i.e. we're using the local macro configuration option from Velocity). <property> <name>velocimacro.permissions.allow.inline.local.scope</ name> <value>true</value> </property> However for the include feature of XWiki Syntax 1.0 to work we have a hack in the velocity module to allow macros to span more than 1 document. This is not required for the XWiki Syntax 2.0 (AFAIR) but we need it for the 1.0 syntax to continue working. Thanks -Vincent
I have modified my dbstringlist SQL query to use only one column to be sure this is the easiest case... I then add a listitem manually to the list property of the object in my velocity script. Everything is OK but sometimes the list item appears in the object editor, sometimes not and i don't understand why yet!
It should always be there. The code says that if the selected item is not in the list obtained from the DB, then it is manually added at the end.
Still investigating!
best regards PAscal
On Thu, Oct 2, 2008 at 6:22 PM, Pascal Voitot <[email protected]>wrote:
plz see below
thks Pascal
On Thu, Oct 2, 2008 at 6:01 PM, Sergiu Dumitriu <[email protected]> wrote:
Pascal Voitot wrote:
hello guys, I do the following: - I have a class with a DBStringList property "mylist" - In a velocity script, I do: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.get("mylist")) #set($mylist = "${mylist}|${mynewlistitem}") #set($ret = $obj.set("mylist", $mylist))
#set($ret = $doc.save())
- I run this script and I can see in the DB that "mynewlistitem" was added as listitem to "mylist" but the item doesn't appear in the object editor for property "mylist" in my document. - Moreover, I get some rendering exception in contentview.vm when I try to access this object in other velocity scripts. - When I create the link using the Object editor, then everything works well but I don't see anything different in the DB from the previous state.
- I have tried the same with: #set($obj = $doc.getObject("MyClass", $mynb)
#set($mylist = $obj.getProperty("mylist").getValue()) #set($ret = $mylist.add("${mynewlistitem}"))
#set($ret = $doc.save())
same result...
It seems the Object property is saved but it is not taken into account by the object in the document.
Do you any clue for me?
- is the property multiselect? relational storage?
multiselect relation storage
- would the mynewlistitem value be returned by the DB search? Or is it a new value you want to include manually?
in Object editor, I use the DB search to return this value (which is stored in DB) plus another string (which is the displayed value)
select myvalue, mystring from ...
In my velocity script, I had this value manually directly accessing the property... But after that, I verify it has been stored using the Object editor...
- does the DB query normally return one or two values?
2 values
- what exactly is the error you receive?
I don't have it here now but this is a kind of StackOverflow in getRenderedContent()
I will search with the debugger if you don't have any quick idea... In fact, as my property is well stored in the DB (I have verified manually), I don't see the wrong interaction between this property and its object in this case... what's different between accessing the property from the object editor or from my velocity script?
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Vincent Massol wrote:
On Oct 3, 2008, at 12:18 PM, Sergiu Dumitriu wrote:
Pascal Voitot wrote:
OK, I don't have solved everything but I have found the origin of the stackoverflow... I coded a Recursive VelocityMacro and apparently variables inside VM macro are not local and it makes my recursion infinite!!! Apparently, there is an option in velocity to make local macro variables have only a local scope. Do you see any problem about this? Yes, I had my share of pain with the fact that variables defined inside macros are global... I am +1 for making them local, but all the macros should be checked, since some of them might use this "feature".
Velocity Macros *are* local (i.e. we're using the local macro configuration option from Velocity).
<property> <name>velocimacro.permissions.allow.inline.local.scope</ name> <value>true</value> </property>
However for the include feature of XWiki Syntax 1.0 to work we have a hack in the velocity module to allow macros to span more than 1 document. This is not required for the XWiki Syntax 2.0 (AFAIR) but we need it for the 1.0 syntax to continue working.
Vincent, this is not about macros, but about $variables used in macros. For example: #macro(doSomething) #set($a = 'b') #end #doSomething() $a => prints b, $a is now a global variable outside the scope of the macro. -- Sergiu Dumitriu http://purl.org/net/sergiu/
On Oct 3, 2008, at 1:17 PM, Sergiu Dumitriu wrote:
Vincent Massol wrote:
On Oct 3, 2008, at 12:18 PM, Sergiu Dumitriu wrote:
Pascal Voitot wrote:
OK, I don't have solved everything but I have found the origin of the stackoverflow... I coded a Recursive VelocityMacro and apparently variables inside VM macro are not local and it makes my recursion infinite!!! Apparently, there is an option in velocity to make local macro variables have only a local scope. Do you see any problem about this? Yes, I had my share of pain with the fact that variables defined inside macros are global... I am +1 for making them local, but all the macros should be checked, since some of them might use this "feature".
Velocity Macros *are* local (i.e. we're using the local macro configuration option from Velocity).
<property> <name>velocimacro.permissions.allow.inline.local.scope</ name> <value>true</value> </property>
However for the include feature of XWiki Syntax 1.0 to work we have a hack in the velocity module to allow macros to span more than 1 document. This is not required for the XWiki Syntax 2.0 (AFAIR) but we need it for the 1.0 syntax to continue working.
Vincent, this is not about macros, but about $variables used in macros. For example:
#macro(doSomething) #set($a = 'b') #end
#doSomething() $a => prints b, $a is now a global variable outside the scope of the macro.
oh ok. We can easily add a new parameter to the {{velocity}} macro (as it's done for the {{include}} macro). Thanks -Vincent
On Fri, Oct 3, 2008 at 1:30 PM, Vincent Massol <[email protected]> wrote:
On Oct 3, 2008, at 1:17 PM, Sergiu Dumitriu wrote:
Vincent Massol wrote:
On Oct 3, 2008, at 12:18 PM, Sergiu Dumitriu wrote:
Pascal Voitot wrote:
OK, I don't have solved everything but I have found the origin of the stackoverflow... I coded a Recursive VelocityMacro and apparently variables inside VM macro are not local and it makes my recursion infinite!!! Apparently, there is an option in velocity to make local macro variables have only a local scope. Do you see any problem about this? Yes, I had my share of pain with the fact that variables defined inside macros are global... I am +1 for making them local, but all the macros should be checked, since some of them might use this "feature".
Velocity Macros *are* local (i.e. we're using the local macro configuration option from Velocity).
<property> <name>velocimacro.permissions.allow.inline.local.scope</ name> <value>true</value> </property>
However for the include feature of XWiki Syntax 1.0 to work we have a hack in the velocity module to allow macros to span more than 1 document. This is not required for the XWiki Syntax 2.0 (AFAIR) but we need it for the 1.0 syntax to continue working.
Vincent, this is not about macros, but about $variables used in macros. For example:
#macro(doSomething) #set($a = 'b') #end
#doSomething() $a => prints b, $a is now a global variable outside the scope of the macro.
Yes this is another config property to set to true... In fact, I don't understand why variables are not local by default in velocity... I don't see any serious language where this is not the case... ok velocity is not a language ;)
oh ok. We can easily add a new parameter to the {{velocity}} macro (as it's done for the {{include}} macro).
Do you mean you can modify the velocity engine config on the fly?
Thanks -Vincent
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (3)
-
Pascal Voitot -
Sergiu Dumitriu -
Vincent Massol