http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2273

*** shadow/2273 Thu Jun 21 11:07:14 2001
--- shadow/2273.tmp.11021       Thu Jun 21 11:07:14 2001
***************
*** 0 ****
--- 1,81 ----
+ +============================================================================+
+ | issue with simple math operations in template                              |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 2273                        Product: Velocity                |
+ |       Status: NEW                         Version: 1.1-rc2                 |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version: Windows NT/2K           |
+ |     Priority: Other                     Component: Source                  |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: [EMAIL PROTECTED]                              |
+ |  Reported By: [EMAIL PROTECTED]                                        |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ Trying to add up a total amount for prices or such things within a template 
+ isn't working -- looks like the context variable is resetting itself. I'm using 
+ the latest sources from 1.2-dev (20010621)
+ 
+ Examples (two variations of the same thing, chopped out of my source code):
+ 
+       #set( $totalPrice = 0 )
+       #set( $items = ${bundle.getItems()} )
+       #foreach( $i in $items )
+         #set( $totalPrice = $totalPrice + $i.getPrice() )
+       #end
+       <!-- ${totalPrice} -->
+ 
+       ##Example 2:
+ 
+       #set( $items = ${bundle.getItems()} )
+       #foreach( $i in $items )
+         #if( $totalPrice )
+           #set( $totalPrice = $i.getPrice() + $totalPrice )
+         #else
+           #set( $totalPrice = $i.getPrice() )
+         #end
+         <!-- ${totalPrice} -->
+       #end
+ 
+ Assume the items in question being looped through (yes, they are displaying 
+ properly) all have a price of $7, and there are 4 of them. The price is 
+ returned from a Java object which has a public double getPrice() method defined.
+ 
+ The first example returns:
+ 
+ <!-- -->
+ <!-- -->
+ <!-- -->
+ <!-- -->
+ 
+ The second example returns:
+ 
+ <!-- 7.0 -->
+ <!-- 7.0 -->
+ <!-- 7.0 -->
+ <!-- 7.0 -->
+ 
+ Obviously, what I wanted was:
+ 
+ <!-- 7.0 -->
+ <!-- 14.0 -->
+ <!-- 21.0 -->
+ <!-- 28.0 -->
+ 
+ My velocity.properties:
+ resource.loader.1.resource.path = e:\\path\\to\\templates
+ file.resource.loader.path = e:\\path\\to\\templates
+ file.resource.loader.modificationCheckInterval = 30
+ file.resource.loader.cache = true
+ velocimacro.permissions.allow.inline = true
+ velocimacro.permissions.allow.inline.local.scope = true
+ velocimacro.context.localscope = false
+ parser.pool.size = 20
+ 
+ My system is Windows NT 4 running JDK1.3 and I'm using this with Tomcat 3.2.1
+ 
+ Please don't hesitate to contact me if you need a better example (or help 
+ reproducing this problem). Obviously I got the 2 examples because I created the 
+ second in an attempt to work around the first one. Thanks for your help!
\ No newline at end of file

Reply via email to