cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe LAPLANCHE" <philippe.laplan...@horus-si.com>
Subject petstore explaination needed
Date Thu, 30 Mar 2006 14:41:06 GMT
Hello,

I'm trying to understand the petstore sample and I hoped someone could
help me understand how the following code works. 

function main(funName) {
    var fun = this[funName];
    var args = new Array(arguments.length -1);
    for (var i = 1; i < arguments.length; i++) {
        args[i-1] = arguments[i];
    }
    getPetStore();
    fun.apply(args);
}

What I understand here is that the only purpose of the function called
"main" is to be sure that it is called each time a request matches *.do

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

I don't understand why we fetch other arguments, arguments.length should
always equal one.

I tried to copy-paste this in my own application because I need that
too. It doesn't work. In my application fun stays empty so
fun.apply(args) doesn't work ...
In my application funName takes the value of the "page" parameter

Also I don't any function called "apply" in javascript and I don't
understand what this[funName] should return... I'm lost here.

Also I don't understand something else in the pagination management (for
example in the function viewCategory() in petstore.js) 
I don't get why we need the cocoon.createPageLocal(). 

>From what I understand about continuations, Cocoon automatically creates
a continuation when we call sendPageAndWait(). So Cocoon should
automatically remember the values of rowcount and skipmaxresults without
having to call createPageLocal(). There's something that I don't get
here.

The code is below. Thanks in advance for your help and the time given.

Philippe

function viewCategory() {
    var categoryId = cocoon.request.get("categoryId");
    var category = getPetStore().getCategory(categoryId);
    var maxResults = MAX_RESULTS;
    /* page local variable to keep track of pagination */
    var local = cocoon.createPageLocal();
    local.skipResults = 0;
    while (true) {
        var productList =
            getPetStore().getProductListByCategory(categoryId,
                                                   local.skipResults,
                                                   maxResults);
        local.lastPage = !productList.isLimitedByMaxRows;
        local.rowCount = productList.rowCount;
        var contextData = {
            accountForm: accountForm,
            productList: productList.rows,
            category: category,
            firstPage: local.skipResults == 0,
            lastPage: local.lastPage
        };
        cocoon.sendPageAndWait("view/Category" + EXT, 
                               contextData, 
                               function () {
                                   /* release contextData and
productList */
                                   contextData = null;
                                   productList = null;
                               });
        var page = cocoon.request.get("page");
        if (page == "previous") {
            if (local.skipResults != 0) {
                local.skipResults -= maxResults;
            }
        } else if (page == "next") {
            if (!local.lastPage) {
                local.skipResults += local.rowCount;
            }
        }
    }
}








I also 



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


Mime
View raw message