Hello. I wonder if anyone can help me with this please. In our documents we often need to uses derived data and not just raw data. For example, if I obtain the monthly price value, say, from our database, how can I display, say, the 6 month price? Does the 6 month value need to be obtained from the data provider, or is there a way of manipulating the raw data value of one month in the template?
Hello nboyd.
Docmosis doesn't allow much logic in the templates. This is intentional since the templates are meant to be presentation-oriented as opposed to code-oriented.
You have three options:
1) calculate the data you require the template to display and add it to the DataProvider in whatever for you wish to display
2) use a Docmosis renderer to call back into your code to apply logic to how a value should be displayed
3) use Java objects as your data source and have the template call methods on the java objects to compute what you require.
As you can tell these options don't let you actually do the computation in the template. The majority of the business logic is intended to be elsewhere.
We suggest #1 as your best general option using a code layer that prepares data for presentation for reports and then has the report generated. This approach allows:
- much easier debugging since you can dump all your data to compare with what you are trying to render in a report. Reflection and Renderers make this much more complex.
- business logic is in a single location (not spread into your templates)
- data can be sourced (and verified) from as many sources as you require prior to producing a report.
Hello paulj,
Many thanks for this - the information I was looking for. It does make a great deal of sense to keep all the business logic out of the templates and just use them for presentation. And thank you for the possible solutions and advice.
