IncludeForm Macro

classic Classic list List threaded Threaded
4 messages Options
A M
Reply | Threaded
Open this post in threaded view
|

IncludeForm Macro

A M
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.
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: IncludeForm Macro

Ludovic Dubost-2
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
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/devs
>
>  


--
Ludovic Dubost
Blog: http://blog.ludovic.org/
XWiki: http://www.xwiki.com
Skype: ldubost GTalk: ldubost

_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Reply | Threaded
Open this post in threaded view
|

Re: IncludeForm Macro

Tiago Rinck Caveden
Hello Ludovic,

On Sun, May 18, 2008 at 3:58 AM, Ludovic Dubost <[hidden email]> 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
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs
Tiago Rinck Caveden
http://caveden.multiply.com
Reply | Threaded
Open this post in threaded view
|

Re: IncludeForm Macro

Sergiu Dumitriu-2
Tiago Rinck Caveden wrote:

> Hello Ludovic,
>
> On Sun, May 18, 2008 at 3:58 AM, Ludovic Dubost <[hidden email]> 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/
_______________________________________________
devs mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/devs