Map of maps totally works, but you're all confused. If it doesn't work,
you can always do things in two steps, so you know which one is not working:
#set( $storedMap = $storedValues.get($dynamicStringVariable) )
Then see if you actually got your map before trying to get the hour. If
your key is actually a String, you need to do:
Map is $storedValues.get("$dynamicStringVariable")
And nevermind conversions. If your key is actually an Integer, then
$dynamicStringVariable better damn well be an Integer, no?
#set( $actuallyAnInteger = 3 )
#set( $actuallyAString = "3" )
#set( $alsoAString = "$actuallyAnInteger" )
$actuallyAnInteger.Class.Name is java.lang.Integer
$actuallyAString.Class.Name is java.lang.String
$alsoAString is java.lang.String
Get it? Remember these are just Java objects after all-- there is no
magic here. When you get that Map above, try
$storedMap.Class.Name
And if you see the template text right there, you didn't actually get
your map...
Of course if you were writing objects to be used by Velocity or any
template language for that matter, including JSP, you would never do
this to yourself-- you would make sure your keys were strings, and you
would probably avoid doing map-of-list-of-map-of-lists because that can
induce headaches. If you can write Java code, then you always have the
option of decorating whatever objects you're getting from this code you
have to decompile, instead of having to deal with those objects in the
template directly.
--jason
Daniel Brownell wrote:
Hi,
I have 2 questions: the first, is, can I get from an int to an integer
in the VTL, as so:
$Integer.getInteger($String.valueOf($myInt))?
It just prints all that text back out, so I don't know if it works.
Second,
What is the VTL syntax for using a map of maps.
Has anyone had any luck implementing this?
Lets say this is my code:
HashMap storedValues = new HashMap();
for (int I = 0; I < 5; I++) {
HashMap times = new HashMap();
times.put("hour", somevalue[i]);
times.put("min", someothervalue[i]);
storedValues.put(arrayOfStrings[i], times);
}
context.put("storedValues", storedValues);
Now how do I get to somevalue[i] from VTL?
$storedValues.get($dynamicStringVariable).get("hour") sure doesn't work.
Please help,
Dan
(The connection between my questions is because $dynamicStringVariable
is actually created by conversion from an int)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]