Hello,

On Mon, Jan 31, 2011 at 11:45 AM, Piotr Dziubecki <[email protected]>wrote:

> Dear all,
>
> I'm trying to extend a FAQ application from the tutorial on xwiki site.
>
> I would like to add some FAQ entries from the external file in an automated
> or semi-automated way.
>
> In the FAQ example there are: question, answer fields for every FAQ entry.
> Is it possible to add new entries
> basing on the external data user provided ?
>
> like to take a data from a text area in a form like:
>
> "question1", "answer1"
> "question2", "answer2"
>
> and then create 2 new FAQ objects ?
>
> I've found such a code snippet and fixed it to have:
>
> ## Create an object
> #set($obj = $doc.newObject("FAQ.FAQClass"))
> $obj.set("question","q1")
> $obj.set("answer", "a1")
>
> ## Save the object in the page
> $doc.save()
>

As long as you have edit rights on the current document ($doc), the code
above should work fine.
Are you sure FAQ.FAQClas exists?


>
> Even with that it fails to add new object to the existing list. Any clues
> how to accomplish that ?
>
> Just to recap, I have two questions :
>
> 1. Could someone provide a code snippet, or point me to a documentation on
> creating/adding new objects in
> the xwiki ( like how to set parentSpace, basic fields in that object and
> add it to the xwiki database ).
>

Check out the documentation for the current API:
http://platform.xwiki.org/xwiki/bin/view/DevGuide/API/ .
For example, in order to set the parent of the current document, the
following code lines:

$doc.setParent('ParentSpaceName.ParentPageName')
$doc.save()

should do the trick.


>
> 2. Are there any scenarios on importing data in to the XWiki ( would like
> to inject a lot of FAQ entries at
> once, tried to do that directly to the database but that failed, I guess I
> should do that via velocity code ? ).


What you can do is to use an Excel file, attach it to a document inside your
XWiki Enterprice instance, then get it with Velocity, parse its content
(line by line) and inject the data into your instance.

Raluca.



>
> Thanks a lot for any help :)
>
> Regards,
> Piotr
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to