coliver     2003/03/19 10:18:44

  Modified:    src/scratchpad/webapp/samples/petstore/flow petstore.js
  Log:
  fixed bug in next/prev processing and added example of catch(break/continue)
  
  Revision  Changes    Path
  1.5       +53 -24    
cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js
  
  Index: petstore.js
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- petstore.js       17 Mar 2003 15:23:39 -0000      1.4
  +++ petstore.js       19 Mar 2003 18:18:43 -0000      1.5
  @@ -104,13 +104,13 @@
       var cartItems = [];
       for (var i in cartForm.cart.cartItems) {
           var cartItem = cartForm.cart.cartItems[i];
  -     cartItems.push(cartItem);
  +        cartItems.push(cartItem);
       }
       sendPage("/view/Cart.html", {
                accountForm: accountForm, 
                cartForm: cartForm, 
                yoshi: yoshi,
  -                           cartItems: cartItems
  +             cartItems: cartItems
   
       });
   }
  @@ -122,12 +122,12 @@
       var cartItems = [];
       for (var i in cartForm.cart.cartItems) {
           var cartItem = cartForm.cart.cartItems[i];
  -     cartItems.push(cartItem);
  +        cartItems.push(cartItem);
       }
       sendPage("/view/Cart.html", {
                yoshi: yoshi, 
                accountForm: accountForm, 
  -                     cartForm: cartForm, cartItems: cartItems
  +                        cartForm: cartForm, cartItems: cartItems
       });
   }
   
  @@ -138,13 +138,13 @@
           var itemId = cartItem.item.itemId;
           var quantity = new java.lang.Double(cocoon.request.get(itemId)).intValue();
           cartItem.updateQuantity(quantity);
  -     cartItems.push(cartItem);
  +        cartItems.push(cartItem);
       }
       sendPage("/view/Cart.html", {
                yoshi: yoshi, 
                accountForm: accountForm, 
  -          cartForm:cartForm,
  -          cartItems: cartItems
  +             cartForm:cartForm,
  +             cartItems: cartItems
       });
   }
   
  @@ -155,12 +155,13 @@
       var cartItems = [];
       for (var i in cartForm.cart.cartItems) {
           var cartItem = cartForm.cart.cartItems[i];
  -     cartItems.push(cartItem);
  +        cartItems.push(cartItem);
       }
       sendPage("/view/Cart.html", {
                yoshi: yoshi, 
                accountForm: accountForm, 
  -                     cartForm:cartForm, cartItems: cartItems
  +             cartForm:cartForm, 
  +             cartItems: cartItems
       });
   }
   
  @@ -173,21 +174,39 @@
       var skipResults = 0;
       var maxResults = MAX_RESULTS;
       while (true) {
  -        var productList = getPetStore().getProductListByCategory(categoryId,
  -                                                                 skipResults, 
  -                                                                 maxResults);
  +        var productList = 
  +            getPetStore().getProductListByCategory(categoryId,
  +                                                   skipResults, 
  +                                                   maxResults);
  +        var lastPage = !productList.isLimitedByMaxRows;
  +        var rowCount = productList.rowCount;
           sendPageAndWait("/view/Category.html", {
                           accountForm: accountForm, 
                           productList: productList.rows, 
                           category: category, 
                           firstPage: skipResults == 0, 
  -                        lastPage: !productList.isLimitedByMaxRows
  +                        lastPage: lastPage
           });
  +
  +        catch (break) {
  +            print("zapping productList");
  +            productList = null;
  +        }
  +        
  +        catch (continue) {
  +            print("returning from continuation");
  +            print("productList="+productList);
  +        }
  +
           var page = cocoon.request.get("page");
           if (page == "previous") {
  -            skipResults -= maxResults;
  +            if (skipResults != 0) {
  +                skipResults -= maxResults;
  +            }
           } else if (page == "next") {
  -            skipResults += productList.rowCount;
  +            if (!lastPage) {
  +                skipResults += rowCount;
  +            }
           }
       } 
   }
  @@ -201,9 +220,10 @@
       var maxResults = MAX_RESULTS;
   
       while (true) {
  -        var itemList = getPetStore().getItemListByProduct(productId,
  -                                                          skipResults, 
  -                                                          maxResults);
  +        var itemList = 
  +            getPetStore().getItemListByProduct(productId,
  +                                               skipResults, 
  +                                               maxResults);
           sendPageAndWait("/view/Product.html", {
                           accountForm: accountForm, 
                           yoshi: yoshi,
  @@ -214,9 +234,13 @@
           });
           var page = cocoon.request.get("page");
           if (page == "previous") {
  -            skipResults -= maxResults;
  +            if (skipResults != 0) {
  +                skipResults -= maxResults;
  +            }
           } else if (page == "next") {
  -            skipResults += itemList.rowCount;
  +            if (!itemList.isLimitedByMaxRows) {
  +                skipResults += itemList.rowCount;
  +            }
           } 
       }
   }
  @@ -309,8 +333,9 @@
       var skipResults = 0;
       var maxResults = 3;
       while (true) {
  -        var result = getPetStore().searchProductList(keyword, skipResults,
  -                                                     maxResults);
  +        var result = 
  +            getPetStore().searchProductList(keyword, skipResults,
  +                                            maxResults);
           sendPageAndWait("/view/SearchProducts.html", {
                           searchResultsProductList: result.rows,
                           firstPage: skipResults == 0,
  @@ -318,9 +343,13 @@
           });
           var page = cocoon.request.get("page");
           if (page == "previous") {
  -            skipResults -= maxResults;
  +            if (skipResults != 0) {
  +                skipResults -= maxResults;
  +            }
           } else if (page == "next") {
  -            skipResults += result.rowCount;
  +            if (!result.isLimitedByMaxRows) {
  +                skipResults += result.rowCount;
  +            }
           }
       }
   }
  
  
  

Reply via email to