Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

BJ Freeman
I hope that groovy does collects memory after each iteration.
otherwise there would be a lot of wasted memory.

[hidden email] sent the following on 8/1/2008 4:19 PM:

> Author: lektran
> Date: Fri Aug  1 16:19:29 2008
> New Revision: 681898
>
> URL: http://svn.apache.org/viewvc?rev=681898&view=rev
> Log:
> Some sort of problem with variable scope when using methods written in groovy scripts, I don't really understand it but the problem is fixed at least
>
> Modified:
>     ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
>
> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy?rev=681898&r1=681897&r2=681898&view=diff
> ==============================================================================
> --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy (original)
> +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy Fri Aug  1 16:19:29 2008
> @@ -40,13 +40,13 @@
>  import org.ofbiz.order.shoppingcart.ShoppingCartEvents;
>  
>  String buildNext(Map map, List order, String current, String prefix, Map featureTypes) {
> -    ct = 0;
> -    buf = new StringBuffer();
> +    def ct = 0;
> +    def buf = new StringBuffer();
>      buf.append("function listFT" + current + prefix + "() { ");
>      buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options.length = 1;");
>      buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options[0] = new Option(\"" + featureTypes[current] + "\",\"\",true,true);");
>      map.each { key, value ->
> -        optValue = null;
> +        def optValue = null;
>  
>          if (order.indexOf(current) == (order.size()-1)) {
>              optValue = value.iterator().next();
> @@ -61,8 +61,8 @@
>      if (order.indexOf(current) < (order.size()-1)) {
>          ct = 0;
>          map.each { key, value ->
> -            nextOrder = order.get(order.indexOf(current)+1);
> -            newPrefix = prefix + "_" + ct;
> +            def nextOrder = order.get(order.indexOf(current)+1);
> +            def newPrefix = prefix + "_" + ct;
>              buf.append(buildNext(value, order, nextOrder, newPrefix, featureTypes));
>              ct++;
>          }
>
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

Scott Gray
Hi BJ

I really don't think garbage collection (if that's what you mean) has
anything to do with the problem, it's simply a matter of understanding
how groovy's variable scope differs from what we had in bsh.  I'm
going to play around with it a bit more when I get a chance.

Regards
Scott

2008/8/2 BJ Freeman <[hidden email]>:

> I hope that groovy does collects memory after each iteration.
> otherwise there would be a lot of wasted memory.
>
> [hidden email] sent the following on 8/1/2008 4:19 PM:
>> Author: lektran
>> Date: Fri Aug  1 16:19:29 2008
>> New Revision: 681898
>>
>> URL: http://svn.apache.org/viewvc?rev=681898&view=rev
>> Log:
>> Some sort of problem with variable scope when using methods written in groovy scripts, I don't really understand it but the problem is fixed at least
>>
>> Modified:
>>     ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
>>
>> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy
>> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy?rev=681898&r1=681897&r2=681898&view=diff
>> ==============================================================================
>> --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy (original)
>> +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy Fri Aug  1 16:19:29 2008
>> @@ -40,13 +40,13 @@
>>  import org.ofbiz.order.shoppingcart.ShoppingCartEvents;
>>
>>  String buildNext(Map map, List order, String current, String prefix, Map featureTypes) {
>> -    ct = 0;
>> -    buf = new StringBuffer();
>> +    def ct = 0;
>> +    def buf = new StringBuffer();
>>      buf.append("function listFT" + current + prefix + "() { ");
>>      buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options.length = 1;");
>>      buf.append("document.forms[\"addform\"].elements[\"FT" + current + "\"].options[0] = new Option(\"" + featureTypes[current] + "\",\"\",true,true);");
>>      map.each { key, value ->
>> -        optValue = null;
>> +        def optValue = null;
>>
>>          if (order.indexOf(current) == (order.size()-1)) {
>>              optValue = value.iterator().next();
>> @@ -61,8 +61,8 @@
>>      if (order.indexOf(current) < (order.size()-1)) {
>>          ct = 0;
>>          map.each { key, value ->
>> -            nextOrder = order.get(order.indexOf(current)+1);
>> -            newPrefix = prefix + "_" + ct;
>> +            def nextOrder = order.get(order.indexOf(current)+1);
>> +            def newPrefix = prefix + "_" + ct;
>>              buf.append(buildNext(value, order, nextOrder, newPrefix, featureTypes));
>>              ct++;
>>          }
>>
>>
>>
>>
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

Ean Schuessler
Looks like the variables were never declared? Groovy is soft-typed but it still wants you to def a variable before its used.

----- "Scott Gray" <[hidden email]> wrote:

> I really don't think garbage collection (if that's what you mean) has
> anything to do with the problem, it's simply a matter of
> understanding
> how groovy's variable scope differs from what we had in bsh.  I'm
> going to play around with it a bit more when I get a chance.

--
Ean Schuessler, CTO Brainfood.com
[hidden email] - http://www.brainfood.com - 214-720-0700 x 315
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

Scott Gray
http://groovy.codehaus.org/Scoping+and+the+Semantics+of+%22def%22#ScopingandtheSemanticsof%22def%22-Sowhatisdifferent%3F

Scripts are different in that assigning undeclared variables puts them
in the binding which it appears methods also have access to.

Regards
Scott

2008/8/2 Ean Schuessler <[hidden email]>:

> Looks like the variables were never declared? Groovy is soft-typed but it still wants you to def a variable before its used.
>
> ----- "Scott Gray" <[hidden email]> wrote:
>
>> I really don't think garbage collection (if that's what you mean) has
>> anything to do with the problem, it's simply a matter of
>> understanding
>> how groovy's variable scope differs from what we had in bsh.  I'm
>> going to play around with it a bit more when I get a chance.
>
> --
> Ean Schuessler, CTO Brainfood.com
> [hidden email] - http://www.brainfood.com - 214-720-0700 x 315
>
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

BJ Freeman
looks like def is undefined till used
unless you do a string or int
also looks like they use casting.

Scott Gray sent the following on 8/1/2008 7:57 PM:

> http://groovy.codehaus.org/Scoping+and+the+Semantics+of+%22def%22#ScopingandtheSemanticsof%22def%22-Sowhatisdifferent%3F
>
> Scripts are different in that assigning undeclared variables puts them
> in the binding which it appears methods also have access to.
>
> Regards
> Scott
>
> 2008/8/2 Ean Schuessler <[hidden email]>:
>> Looks like the variables were never declared? Groovy is soft-typed but it still wants you to def a variable before its used.
>>
>> ----- "Scott Gray" <[hidden email]> wrote:
>>
>>> I really don't think garbage collection (if that's what you mean) has
>>> anything to do with the problem, it's simply a matter of
>>> understanding
>>> how groovy's variable scope differs from what we had in bsh.  I'm
>>> going to play around with it a bit more when I get a chance.
>> --
>> Ean Schuessler, CTO Brainfood.com
>> [hidden email] - http://www.brainfood.com - 214-720-0700 x 315
>>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r681898 - /ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/entry/catalog/ProductDetail.groovy

BJ Freeman
the reason I mention  this is it is better to use
int if that is what it is going to be used for
other wise you don't have type checking.

BJ Freeman sent the following on 8/1/2008 8:10 PM:

> looks like def is undefined till used
> unless you do a string or int
> also looks like they use casting.
>
> Scott Gray sent the following on 8/1/2008 7:57 PM:
>> http://groovy.codehaus.org/Scoping+and+the+Semantics+of+%22def%22#ScopingandtheSemanticsof%22def%22-Sowhatisdifferent%3F
>>
>> Scripts are different in that assigning undeclared variables puts them
>> in the binding which it appears methods also have access to.
>>
>> Regards
>> Scott
>>
>> 2008/8/2 Ean Schuessler <[hidden email]>:
>>> Looks like the variables were never declared? Groovy is soft-typed but it still wants you to def a variable before its used.
>>>
>>> ----- "Scott Gray" <[hidden email]> wrote:
>>>
>>>> I really don't think garbage collection (if that's what you mean) has
>>>> anything to do with the problem, it's simply a matter of
>>>> understanding
>>>> how groovy's variable scope differs from what we had in bsh.  I'm
>>>> going to play around with it a bit more when I get a chance.
>>> --
>>> Ean Schuessler, CTO Brainfood.com
>>> [hidden email] - http://www.brainfood.com - 214-720-0700 x 315
>>>
>>
>>
>
>
>
>