Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Building HTML

 
Richard Hooper
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Can anyone give me a few hints?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would bind the array to one of the scoped objects, forward to a JSP, and then build the HTML by iterating over the array with JSTL.
 
Richard Hooper
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Richard Hooper
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll have a fiddle, looks good! Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic