[xwiki-users] Javascript + velocity Integration
Hello Community, Can I use velocity methods inside my JS code? For example, I want to parse my JSON text to Java objects inside a JS function: <js code> Function function (){ Var test = $jsontool.parse('["json string"]') } Function(); </js code> Is it possible? Thanks Danilo Grupo Energisa Danilo Oliveira Analista Suporte Aplicacao TI - DPTO CORP. DE INFRAESTR. TI e-mail: [email protected] | tel: (32) 3429-6342 | cel: (32) 8452-9478 Esta mensagem contém informação confidencial. Se você a recebeu por engano, não divulgue ou copie seu conteúdo. Por favor, avise ao remetente imediatamente e apague-a do computador. Privileged and confidential. If this message has been received by mistake, do not disclose or copy its contents. Please notify sender and delete immediately.
Hi Danilo, On 26 May 2014 at 20:35:08, Danilo Amaral de Oliveira ([email protected](mailto:[email protected])) wrote:
Hello Community,
Can I use velocity methods inside my JS code? For example, I want to parse my JSON text to Java objects inside a JS function:
Function function (){ Var test = $jsontool.parse('["json string"]') } Function();
Is it possible?
Yes, see http://platform.xwiki.org/xwiki/bin/view/DevGuide/SkinExtensionsTutorial And especially http://platform.xwiki.org/xwiki/bin/view/DevGuide/SkinExtensionsTutorial#HHo... (hint: set “parse” to true). Thanks -Vincent
Thanks
Danilo
Be careful that the Velocity code is executed on the server side, before the JavaScript is evaluated by the browser. The following line doesn't make any sense: var test = $jsontool.parse('["json string"]') 'test' is a JavaScript variable while $jsontool.parse() returns a Java object. 'test' is assigned on the client, in the browser, while $jsontool.parse() is executed on the server. I don't see why you need to parse JSON using Java when JSON means JavaScript Object Notation and there are of course dedicated APIs to parse JSON into JavaScript objects. Hope this helps, Marius On Mon, May 26, 2014 at 9:34 PM, Danilo Amaral de Oliveira <[email protected]> wrote:
Hello Community,
Can I use velocity methods inside my JS code? For example, I want to parse my JSON text to Java objects inside a JS function: <js code> Function function (){ Var test = $jsontool.parse('["json string"]') } Function(); </js code>
Is it possible?
Thanks
Danilo
Grupo Energisa Danilo Oliveira Analista Suporte Aplicacao TI - DPTO CORP. DE INFRAESTR. TI e-mail: [email protected] | tel: (32) 3429-6342 | cel: (32) 8452-9478
Esta mensagem contém informação confidencial. Se você a recebeu por engano, não divulgue ou copie seu conteúdo. Por favor, avise ao remetente imediatamente e apague-a do computador. Privileged and confidential. If this message has been received by mistake, do not disclose or copy its contents. Please notify sender and delete immediately.
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
Danilo Amaral de Oliveira -
Marius Dumitru Florea -
vincent@massol.net