How to process a bean and hash at the same time?

ipolevoy <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hello, I'm working on a framework and considering using Freemarker for UI
layer. In order to achieve this, I will need the engine to recognize objects
as beans and maps at the same time. In other words, I would have a class:

public class Person extends HashMap {
    private String name;
    public Person(String name) {name = name;}
    public String getName() {return name;}
}


Merging code:

Map root = new HashMap();
Person p = new Person("John");
p.put("age", 39);
root.put("da_bean", p);
template.process(root, out);

...and the template:

Map: ${da_bean.age}
&lt;br&gt;
Bean: ${da_bean.name}

The class Person is a Map and is also a bean (has a "name" property). I
looked at the documentation, API and source code, and it seems that I will
have to write a custom wrapper and a template model, but without a good
understanding of the internal architecture, this might be a whole new
project.

Is there a way to achieve this easier? Am I going in the wrong direction?

Thanks much for all the help!

igor 
-- 
View this message in context: http://freemarker.624813.n4.nabble.com/How-to-process-a-bean-and-hash-at-the-same-time-tp2217465p2217465.html
Sent from the freemarker-user mailing list archive at Nabble.com.

------------------------------------------------------------------------------

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.