Re: instanceOf and/or isAssignableFrom operator in freemarker
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, April 23, 2009, 1:07:47 PM, Daniel Dekany wrote: > Wednesday, April 22, 2009, 8:49:41 PM, dlevancho wrote: >> >> Hi, >> >> I am trying to find a way to test if a certain object implements certain >> Interface, or at lease if it is instance eof certain class,but as I >> understand freemarker does not support that operator? > > It doesn't. I mean, not out-of-the-box. The template language (FTL) > doesn't even know the idea of classes, it only has numbers, string, > boolean, hashes, sequences, and a few more such basic types. Actually, > this issues is pretty clearly data-model related (certain entries in > the data-model should be able to tell if they are a YouKnowWhat). > >> I would low to see a isAssignableFrom check or at least instanceOf >> operator, but so far I have not seen a word mention about them in >> freemarker manual . can anyone help me out with a workaround? > > For now, you can either write a TemplatMethodModel Sorry, a TemplateMethodModelEx... > for it, or extend > the object wrapper (BeansWrapper). Or, maybe you can use duck-typing. > I believe this is pretty clearly a data-model issue, and as such I > would advise to solve it be customizing BeansWrapper (see also: > Configuration.setObjectWrapper). > > Actually, Attila, can't BeansWrapper already do that? I don't know... > I guess it should be able to, given it *is* for exposing Java object > as-is (OK, with some security restrictions and like, but you get what > I mean), and the class is a quite important information for Java > classes, For java objects, I meant... > given that in the Java world duck-typing and like is at best rare. -- Best regards, Daniel Dekany ------------------------------------------------------------------------------ Stay on top of everything new and different, both inside and around Java (TM) technology - register by April 22, and save $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. 300 plus technical and hands-on sessions. Register today. Use priority code J9JMT32. http://p.sf.net/sfu/p