On Thu, Jun 7, 2012 at 3:28 PM, <mathieu.canzerini(a)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'?><test>test</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'?><test>test</test>")
...
$xcontext.setFinished(true)
{{/velocity}}
Thanks for your help.
M. Canzerini
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Thomas Mortagne