You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Derek Hohls <dh...@csir.co.za> on 2005/11/02 13:49:10 UTC

Understanding/extending the PetStore example

I am trying to get a handle on a key function in the PetStore example;
the sitemap handles a call to any function in the sample as follows:

      <map:match pattern="*.do">
        <map:call function="main">
          <map:parameter name="page" value="{1}"/>
        </map:call>
      </map:match>

in the petstore.js code, there is the corresponding match:

function main(funName) {
    var fun = this[funName];
    ...
}

when I use the Rhino JavaScript debugger, it shows clearly
that the value of "funName" in the main(funName) is that of
the function being called.  However, it is not clear as to where/
how that value becomes associated with the function parameter.

In my application, where I try the same type of code, I end up
with a null value for "funName"... but I cannot see where/how 
to get the right value in there.

Any help would be appreciated.

Thanks
Derek


-- 
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.
 
CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html 
 
CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html 
 
For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
HelpDesk@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Understanding/extending the PetStore example

Posted by Upayavira <uv...@odoko.co.uk>.
Derek Hohls wrote:
> I am trying to get a handle on a key function in the PetStore example;
> the sitemap handles a call to any function in the sample as follows:
> 
>       <map:match pattern="*.do">
>         <map:call function="main">
>           <map:parameter name="page" value="{1}"/>
>         </map:call>
>       </map:match>
> 
> in the petstore.js code, there is the corresponding match:
> 
> function main(funName) {
>     var fun = this[funName];
>     ...
> }

That method of defining parameters for flowscript functions relies upon
the order of the parameters within the sitemap, and has therefore been
deprecated. You are recommended to use the cocoon.parameters approach
instead. However, all you are doing, in effect, is setting funName to
whatever {1} was.

> when I use the Rhino JavaScript debugger, it shows clearly
> that the value of "funName" in the main(funName) is that of
> the function being called.  However, it is not clear as to where/
> how that value becomes associated with the function parameter.
> 
> In my application, where I try the same type of code, I end up
> with a null value for "funName"... but I cannot see where/how 
> to get the right value in there.

So, funName is the name of a function. As functions are defined within
the current scope (this), this[funName] gets you the function with that
name. Note, it doesn't execute it. You can now execute that function
with fun(), or fun(some, set, of, parameters);

> Any help would be appreciated.

Does that help?

Regards, Upayavira

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org