Re: Hashes (in general)
Brian Pontarelli <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
On Jun 10, 2009, at 1:52 AM, Daniel Dekany wrote: > 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... I understand what it does but I'm just not sure that I like it. I see the need for random Objects to present their properties, fields, methods, etc. in the FM language. I also see the need for provide access to collections and other standard types in a clear way. It seems to me that adding the abstract for the first case complicates the second case considerably. I haven't thought about it for nearly as long as you guys have, but for me it is just one of those cases where you see something and it just doesn't quite feel right. > >> - 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. The same type of wrapper is used for everything. It isn't the same instance, but it could be easily if that was an issue. -bp ------------------------------------------------------------------------------ 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