I want to create an HTML table from an array, apply loads of formatting and so on to it, and then output it in a JSP. I was going to do it all from scratch, and then I thought I could start off using XML instead to save myself some work, and then I found there were a whole load of standard HTMLElement etc classes too. But I just don't get how to use them in practice, and it seems hard to find any step-by-step tutorials for newbies!
The thing is, I've got an existing application where the same JSP is used to output all manner of different reports, and they've only just realised that they want some specific formatting on some of bits. I don't want to have to have multiple JSPs if I can help it, and I don't want to fill the JSP with logic to work out how to display everything in all cases - that's why I want to do all the heavy lifting at the servlet end. I just can't get my head around using the XML API, even though it seems to be just the thing!
I may end up doing it some other way in the end, of course!
Check out the FormattedDataSet at www.fdsapi.com (one of my open source projects). It can create dynamic text (html, xml, and more) from tabular data (ResultSets, arrays and more). You can point the same data at different formatting templates. The API comes with a few default templates (xml, html table and a few others), and you can easily create more.
Here is how the code would work:
It is simple and fast. There is a live demo at the sight that creates dynamic content. If you have any questions let me know. [ January 30, 2006: Message edited by: steve souza ]