Re: Hashes (in general)
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Tuesday, June 9, 2009, 4:57:11 PM, Brian Pontarelli wrote: > > With the proper wrapper you can access the Java Map facility (i.e., > you can use non-string keys; see Attila's answer), but the FTL hash > type is defined as something that associates *strings* with arbitrary > values. So it's not the same as Java's Map-s. For that reason > myMap[key] will always expect a string in FTL. Anyway, I think that a > template language should rather have something like Java's Map-s than > something like FTL's hashes... but in 2.4 the hash type still only > allow string keys. > > > I agree. The template language capable of handling all the cases for > non-string keys, include complex object keys. Seem simple to me. The > whole wrapping process is somewhat interesting to me in general. Not > sure if I like it or not yet. Object wrapping gives you the power to show the "business objects" to template in a way you want. It's quite powerful thing. However, it also requires a FreeMarker "expert" around... But most users do OK for the default wrapper (i.e, they don't have to be aware of wrapping), except when it comes to Map-s, where the "keys must be strings" mess starts... > - Is there a way currently to get FM to stop wrapping the Map with an > incorrect version that has String keys and null values? > > Does such thing happen? Maybe it's just that for missing items the > Hash API (also the Java Map API) returns Null. So, myMap["1"] is null, > because indeed there is no item with key "1" (only with key 1). > > Yeah. It doesn't unwrap the map directly. It creates a special Map > that is an adapter with a custom entry set. It definitely can make things messy. What did you use for unwrapping (and what was the ObjectWrapper)? If you use BeansWrapper and call a plain Java method, it should give you back the original Map. > -bp > -- Best regards, Daniel Dekany ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects