Reputation: 466
I have started to user Freemarker to generate some output based on a datamodel. The issue I face is that I keep exposing methods in my datamodel for the sake of my output generation. So I have the feeling to "pollute" my datamodel for the sole sake of my Freemarker template.
Here is an example:
My datamodel, which is an interface in my case, provides this method (changed names and types for illustration):
Collection<MyPojo> getMyPojos();
In order to write the template the way I imagine it, I need to filter some of MyPojo based on some condition. I wanted first to do it in the template itself but it appeared quite complicated to manipulate lists within the template.
So I ended up adding other methods in my interface to cover the needs:
Collection<MyPojo> getAddedMyPojos();
Collection<MyPojo> getRemovedMyPojos();
Reading the Freemarker documentation, I didn't found a way to use some Fremarker API to provide more method to the template processor.
Is there any smarter way with Freemarker to achieve this goal? I would like to keep my interface clean with only the first method. Do I need to create a dedicated datamodel, extending my initial datamodel? Or to create a Map and to inject this one instead of my datamodel (and to populate it with the results of my methods)?
Thanks!
Upvotes: 0
Views: 45
Reputation: 466
As proposed by Glenn Lane it's better to isolate the code for Freemarker. So implementing a dedicated POJO
Upvotes: 0