[xwiki-devs] IncludeForm Macro
Hello developers, Thank you for responding to my previous query. Can you please explain the differences between the following two macros, what advantages does includeInContext provide over the other? 1. includeForm() 2. includeInContext() Having retrieved an object on a page, how can I update some fields of that object and save? Doc.save() saves the document changing its version.... but, doesn't update the object-parameters. What am I missing? Regards, Archana Mettu.
Archana Mettu wrote:
Hello developers,
Thank you for responding to my previous query.
Can you please explain the differences between the following two macros, what advantages does includeInContext provide over the other?
1. includeForm() 2. includeInContext()
They do the same thing except that using includeForm will trigger the Edit button at the top of the page to launch the "inline" mode (form mode) instead of the wiki editor.
Having retrieved an object on a page, how can I update some fields of that object and save? Doc.save() saves the document changing its version.... but, doesn't update the object-parameters. What am I missing?
You can use $doc.getObject(classname) to retrieve an object and manipulate it's properties. Or you can use $doc.updateObjectFromRequest(classname) if you used the standard names for the properties (if you used $doc.display(fieldname, "edit")) Ludovic
Regards, Archana Mettu. _______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
-- Ludovic Dubost Blog: http://blog.ludovic.org/ XWiki: http://www.xwiki.com Skype: ldubost GTalk: ldubost
Hello Ludovic, On Sun, May 18, 2008 at 3:58 AM, Ludovic Dubost <ludovic@xwiki.org> wrote:
Archana Mettu wrote:
Having retrieved an object on a page, how can I update some fields of that object and save? Doc.save() saves the document changing its version.... but, doesn't update the object-parameters. What am I missing?
You can use $doc.getObject(classname) to retrieve an object and manipulate it's properties.
I am trying to do exactly that, with a very silly code, and it doesn't work, the value of the property doesn't change. Take a look at the code: #set($obj = $doc.getObject("Space.MyClass")) #set($obj.accessCounter = $obj.accessCounter + 1) ~~Number of accesses: $obj.accessCounter~~ The value displyed remains the one I defined by editing the object with the object editor, what suggests the second set is not doing what I expected. Do you have any idea of what am I doing wrong? Thanks, -- Tiago Rinck Caveden http://caveden.multiply.com
Tiago Rinck Caveden wrote:
Hello Ludovic,
On Sun, May 18, 2008 at 3:58 AM, Ludovic Dubost <ludovic@xwiki.org> wrote:
Archana Mettu wrote:
Having retrieved an object on a page, how can I update some fields of that object and save? Doc.save() saves the document changing its version.... but, doesn't update the object-parameters. What am I missing?
You can use $doc.getObject(classname) to retrieve an object and manipulate it's properties.
I am trying to do exactly that, with a very silly code, and it doesn't work, the value of the property doesn't change. Take a look at the code:
#set($obj = $doc.getObject("Space.MyClass")) #set($obj.accessCounter = $obj.accessCounter + 1) ~~Number of accesses: $obj.accessCounter~~
The value displyed remains the one I defined by editing the object with the object editor, what suggests the second set is not doing what I expected.
Do you have any idea of what am I doing wrong?
1. $obj.accessCounter is not the property value, but is a shorthand for $doc.display(). 2. In order to make the changes persistent, you must also save the document. #set($obj = $doc.getObject("Space.MyClass")) #set($v = $obj.getProperty("accessCounter").value) ## if this is not a number property, you must also parse it ## #set($v = $util.parseInt($v)) #set($v = $v + 1) $obj.set("accessCounter", $v) $doc.save() -- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (4)
-
Archana Mettu -
Ludovic Dubost -
Sergiu Dumitriu -
Tiago Rinck Caveden