[stringtemplate-interest] Maps with object keys

Caleb Lyness caleb.lyness at ezswitch.net
Fri Nov 23 03:34:25 PST 2007


Hi all,

I have not been keeping up to date with my string template mails... 
perhaps this has been covered before, just point me at the thread if 
already covered...
This is also being tested against ST-3.0.

Here is a segment of a test template:

  $products: {product |
  <tr>
     <td>$product$</td>    
     <td>$report.productReadStats.(product);null="0"$</td>
     <td>$report.productActivationsStats.(product);null="0"$</td>
     <td>$report.productIssuedStats.(product);null="0"$</td>
  </tr>}$

On the model side I had:

public HashMap<*Product*, Integer> productReadStats = new 
HashMap<*Product*, Integer>();
public HashMap<*Product*, Integer> productIssuedStats = new 
HashMap<*Product*, Integer>();
public HashMap<*Product*, Integer> productActivationsStats = new 
HashMap<*Product*, Integer>();

String template would always report the stats as 0 (via the null 
setting). My guess from what I am seeing
is that ST-3.0 is dereferencing *(product)* to a string and not an 
object. When looking up the value in the
map the string does not result in the correct map reference.

Changing my map to a string based key:

public HashMap<*String*, Integer> productReadStats = new 
HashMap<*String*, Integer>();
... etc ...

resulted in the correct values.

Is this a known problem/limitation? Or is this considered the correct 
behaviour. Surely an attempt should be
made to lookup the object directly and then use the object.toString() as 
the key as a 2nd attempt?

Cheers
      Caleb.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071123/b872752f/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3269 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20071123/b872752f/attachment.bin 


More information about the stringtemplate-interest mailing list