Re: [xwiki-users] How to add multiple objects to a page

2014-06-30 Thread Thomas Mortagne
I just tested:

{{velocity}}
## Create an object
#set($obj = $doc.newObject(XWiki.TagClass))
$obj.set(tags, tag0)

#set($obj = $doc.newObject(XWiki.TagClass))
$obj.set(tags, tag1)

#set($obj = $doc.newObject(XWiki.TagClass))
$obj.set(tags, tag2)

## Save the object in the page
$doc.save()
{{/velocity}}

and I get 3 XWiki.TagClass objects added to the page each time I view it.

On Sun, Jun 29, 2014 at 11:39 AM, Matthias Albert
matthias.alb...@gmx.de wrote:
 My code is something like this:

 {{groovy}}
 def importEvents() {
   def attachment = doc.getAttachment('events.csv')
   def events = services.eventTable.loadCsvEventFile(attachment)
   assert events
   // create one object
   events.each { event -
 println (- importing: $event)
 def obj = doc.newObject(Main.Event)
 obj.Title = event.title
 obj.DateTime = event.dateTime
 obj.Place = event.place
   }
   doc.save()
 }
 {{/groovy}}

 The function services.eventTable.loadCsvEventFile returns a list of
 objects of a Event groovy class, by interpreting a CSV attachment, which
 works fine and is not the problem.

 Main.Event is the XWiki class of which the objects are to be created.

 After executing this code, the println statement shows that the events
 list has several instances, but inspection of the objetcs of the page
 shows only one object created, which is the first of the list.

 Invoking doc.save() within the iteration does not improve this.

 The groovy class and the XWiki class are named the same (Event,
 Main.Event, respectively). Could this be a problem?

 Thank you,
 Matthias


 Am 29.06.2014 09:14, schrieb Thomas Mortagne:
 On Sat, Jun 28, 2014 at 9:23 PM, Matthias Albert matthias.alb...@gmx.de 
 wrote:
 In the dev guide, there is  a description, how to add a single object to
 a page
 (http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAddobjectstoapage).

 Unfortunately, adding multiple objects does not work this way.

 Well It does work this way whatever number of objects. What is your
 code and what issue do you have exactly ?


 Is there any example how to do this?

 Thank you in advance,
 Matthias
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users




 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users



-- 
Thomas Mortagne
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] How to add multiple objects to a page

2014-06-29 Thread Thomas Mortagne
On Sat, Jun 28, 2014 at 9:23 PM, Matthias Albert matthias.alb...@gmx.de wrote:
 In the dev guide, there is  a description, how to add a single object to
 a page
 (http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAddobjectstoapage).

 Unfortunately, adding multiple objects does not work this way.

Well It does work this way whatever number of objects. What is your
code and what issue do you have exactly ?


 Is there any example how to do this?

 Thank you in advance,
 Matthias
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users



-- 
Thomas Mortagne
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] How to add multiple objects to a page

2014-06-29 Thread Matthias Albert
My code is something like this:

{{groovy}}
def importEvents() {
  def attachment = doc.getAttachment('events.csv')
  def events = services.eventTable.loadCsvEventFile(attachment)
  assert events
  // create one object
  events.each { event -
println (- importing: $event)
def obj = doc.newObject(Main.Event)
obj.Title = event.title
obj.DateTime = event.dateTime
obj.Place = event.place
  }
  doc.save()
}
{{/groovy}}

The function services.eventTable.loadCsvEventFile returns a list of
objects of a Event groovy class, by interpreting a CSV attachment, which
works fine and is not the problem.

Main.Event is the XWiki class of which the objects are to be created.

After executing this code, the println statement shows that the events
list has several instances, but inspection of the objetcs of the page
shows only one object created, which is the first of the list.

Invoking doc.save() within the iteration does not improve this.

The groovy class and the XWiki class are named the same (Event,
Main.Event, respectively). Could this be a problem?

Thank you,
Matthias


Am 29.06.2014 09:14, schrieb Thomas Mortagne:
 On Sat, Jun 28, 2014 at 9:23 PM, Matthias Albert matthias.alb...@gmx.de 
 wrote:
 In the dev guide, there is  a description, how to add a single object to
 a page
 (http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAddobjectstoapage).

 Unfortunately, adding multiple objects does not work this way.
 
 Well It does work this way whatever number of objects. What is your
 code and what issue do you have exactly ?
 

 Is there any example how to do this?

 Thank you in advance,
 Matthias
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users
 
 
 

___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


[xwiki-users] How to add multiple objects to a page

2014-06-28 Thread Matthias Albert
In the dev guide, there is  a description, how to add a single object to
a page
(http://platform.xwiki.org/xwiki/bin/view/DevGuide/APIGuide#HAddobjectstoapage).

Unfortunately, adding multiple objects does not work this way.

Is there any example how to do this?

Thank you in advance,
Matthias
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users