2014-05-13 16:04 GMT+02:00 Caleb James DeLisle <[email protected]>:

> This depends a lot on how the javascript is loaded...
>
> If you're including it using $xwiki.jsx.use() then it won't have the same
> context because it's a different HTTP request. If you use the macro and
> then
> do a {{velocity}} macro with an {{html}} macro and a <script> inside of
> that,
> the content will (should) be there.
>
> Another solution is to pass the info in a parameter, eg:
> $xwiki.jsx.use('My.Document', {"param": $value})
> and then in the jsx extension...
>
> var PARAMETER_ONE =
> "$escapetool.javascript($request.getParameter('param'))";
>
> Thanks,
> Caleb
>
>
> On 05/13/2014 03:28 PM, Eduardo Abritta wrote:
> > Exactly. I'm needing initialize a value in the velocity environment and
> use it on the  javascript code.  it not needs to be dinamic.
> > I am trying to use the following code but the JS variable is returning
> "undefined"
> >
> >
> > Java Script Code
> >     var param;
> >     this.param="$xcontext.macro.params.parameter";
> >     console.log(param);
> >
> > Velocity (Macro)
> >
> >      $xcontext.put("param", $xcontext.macro.params.parameter)
>

Did you also check that this $param is correctly set a value in your
velocity code ?
The fact that "param" is undefined on javascript side is strange, if it
didn't find anything in the velocity context, it should contain exactly the
string '$xcontext.macro.params.parameter', not undefined.
So it seems to me it was found in the context, but it has null value.

>
> > Some light?
> >
> > ty
> >
> >
> > Atenciosamente,
> > Eduardo Abritta
> > e-mail: [email protected] |
> >
> >> Date: Tue, 13 May 2014 10:05:17 +0200
> >> From: [email protected]
> >> To: [email protected]
> >> Subject: Re: [xwiki-users] Using parameter macro in the js extension
> >>
> >> Hi,
> >>
> >>
> >> 2014-05-13 8:40 GMT+02:00 Michael Bußler <
> [email protected]>:
> >>
> >>> Hi, the velocity-code is executed on the server, while js-code runs on
> the
> >>> client side, AFTER the macro-code was executed .
> >>> You could try need to pass parameters to your macro via an URL
> parameter or
> >>> http POST.
> >>>
> >>
> >> Only if value needs to be refreshed without a page refresh. If value
> comes
> >> from a velocity macro, it's in the context of a page, so it's enough to
> >> initialize the javascript var from velocity (which is ok as velocity is
> >> executed before) - it's not supposed to be updated server-side after the
> >> page is rendered.
> >> Of course if it needs to be dynamic you could go ajax.
> >> Well my understanding of Eduardo is that he needs to initialize a value
> in
> >> javascript, based on a macro parameter passed to a velocity macro.
> >>
> >>
> >>>
> >>> Hope this helps!
> >>>
> >>> Best, Michael
> >>> Am 12.05.2014 19:01 schrieb "Eduardo Abritta" <
> [email protected]
> >>>> :
> >>>
> >>>> Hi Sirs,
> >>>>
> >>>> I am developing a macro in velocity (wiki macro) and need to use a
> >>>> parameter (wiki macro parameter) defined by the user in my java script
> >>> code
> >>>> (java script extension). I tried  can several methods but it is not
> >>> working.
> >>>>
> >>>> How can I do this?
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> Atenciosamente,
> >>>> Eduardo Abritta
> >>>> e-mail: [email protected] |
> >>>>
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> users mailing list
> >>>> [email protected]
> >>>> http://lists.xwiki.org/mailman/listinfo/users
> >>>>
> >>> _______________________________________________
> >>> users mailing list
> >>> [email protected]
> >>> http://lists.xwiki.org/mailman/listinfo/users
> >>>
> >> _______________________________________________
> >> users mailing list
> >> [email protected]
> >> http://lists.xwiki.org/mailman/listinfo/users
> >
> > _______________________________________________
> > users mailing list
> > [email protected]
> > http://lists.xwiki.org/mailman/listinfo/users
> >
> _______________________________________________
> 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