Re: [xwiki-users] how to generate XML from a velocity script page ?

2012-06-07 Thread Sergiu Dumitriu

On 06/07/2012 09:28 AM, mathieu.canzer...@intech.lu wrote:

Hello everybody,

i need to use Ajax but i can not generate XML from a velocity script page.
Here is a piece of my script :
{{velocity}}
$response.setContentType('application/xml')
#set ($out = $response.getOutputStream())
$out.write(?xml version='1.0' encoding='ISO-8859-1'?testtest/test)
...
{{/velocity}}

But my responseXML is null.

I suppose that it's not the good way to generate XML from velocity.

Thanks for your help.

M. Canzerini


See this other thread:
http://markmail.org/message/tjrnj6zy2n37blua

Short summary, you should call flush() and close() on the stream after 
you're done writing data to it.



--
Sergiu Dumitriu
http://purl.org/net/sergiu/
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


Re: [xwiki-users] how to generate XML from a velocity script page ?

2012-06-07 Thread Thomas Mortagne
On Thu, Jun 7, 2012 at 3:28 PM,  mathieu.canzer...@intech.lu wrote:
 Hello everybody,

 i need to use Ajax but i can not generate XML from a velocity script page.
 Here is a piece of my script :
 {{velocity}}
 $response.setContentType('application/xml')
 #set ($out = $response.getOutputStream())
 $out.write(?xml version='1.0' encoding='ISO-8859-1'?testtest/test)
 ...
 {{/velocity}}

 But my responseXML is null.

 I suppose that it's not the good way to generate XML from velocity.

There is no #write(String) method in OutputStream but
ServletOutputStream (which extends it and which is what you get in
standard XWiki) provide a #print(String) method.

but there is another issue. If you do only that XWiki will still send
all the UI after your actual XML content so your XML parser will not
like that too much.

To avoid that you can use $xcontext.setFinished(true) so your script
should looks like:

{{velocity}}
$response.setContentType('application/xml')
#set ($out = $response.getOutputStream())
$out.print(?xml version='1.0' encoding='ISO-8859-1'?testtest/test)
...
$xcontext.setFinished(true)
{{/velocity}}


 Thanks for your help.

 M. Canzerini

 ___
 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 generate XML from a velocity script page ?

2012-06-07 Thread Thomas Mortagne
On Thu, Jun 7, 2012 at 3:43 PM, Sergiu Dumitriu ser...@xwiki.com wrote:
 On 06/07/2012 09:28 AM, mathieu.canzer...@intech.lu wrote:

 Hello everybody,

 i need to use Ajax but i can not generate XML from a velocity script page.
 Here is a piece of my script :
 {{velocity}}
 $response.setContentType('application/xml')
 #set ($out = $response.getOutputStream())
 $out.write(?xml version='1.0' encoding='ISO-8859-1'?testtest/test)
 ...
 {{/velocity}}

 But my responseXML is null.

 I suppose that it's not the good way to generate XML from velocity.

 Thanks for your help.

 M. Canzerini


 See this other thread:
 http://markmail.org/message/tjrnj6zy2n37blua

 Short summary, you should call flush() and close() on the stream after
 you're done writing data to it.

You can indeed also use $out.flush() and $out.close() instead of
$xcontext.setFinished(true).



 --
 Sergiu Dumitriu
 http://purl.org/net/sergiu/

 ___
 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 generate XML from a velocity script page ?

2012-06-07 Thread mathieu.canzerini
Now it works good thank you !

Mathieu

On Thu, 7 Jun 2012 15:45:42 +0200, Thomas Mortagne
thomas.morta...@xwiki.com wrote:
 On Thu, Jun 7, 2012 at 3:43 PM, Sergiu Dumitriu ser...@xwiki.com wrote:
 On 06/07/2012 09:28 AM, mathieu.canzer...@intech.lu wrote:

 Hello everybody,

 i need to use Ajax but i can not generate XML from a velocity script page.
 Here is a piece of my script :
 {{velocity}}
 $response.setContentType('application/xml')
 #set ($out = $response.getOutputStream())
 $out.write(?xml version='1.0' encoding='ISO-8859-1'?testtest/test)
 ...
 {{/velocity}}

 But my responseXML is null.

 I suppose that it's not the good way to generate XML from velocity.

 Thanks for your help.

 M. Canzerini


 See this other thread:
 http://markmail.org/message/tjrnj6zy2n37blua

 Short summary, you should call flush() and close() on the stream after
 you're done writing data to it.
 
 You can indeed also use $out.flush() and $out.close() instead of
 $xcontext.setFinished(true).
 


 --
 Sergiu Dumitriu
 http://purl.org/net/sergiu/

 ___
 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