• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsp tag for creating an HTML table

 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Could any one please tell me a jsp tag for creating an HTML table in my jsp ?
Thanks
Maya
 
Dane Frazier
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maya,
For a short, simple answer:
You will probably want to use either direct HTML in your page (e.g. <table><tr><td></td><%="some value"%></tr></table>
or output it as part of your internal output structure. (e.g. concat it to some variable - "<TR><TD>The calculated value is <b>" + iSomeVal + "</b></TD></TR>" )
-dane
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add something else to this thread, while outputting lots of HTML code from inside JSP tags is easily achievable, it's not really best practice since you take away the ability for page authors/designers to take away the page and modify the look and feel. In essence, this is for the same reasons behind why JSPs replace(d) Servlets for generating HTML.
With this in mind, given that you need to build a page with tags, there are several ways in which you can minimize the amount of content that custom tags generate. Examples include tags that introduce scripting variables, tags that cooperate on the page, and if you do need to generate HTML, you can use technologies such as CSS to reduce the amount of style information that you put into the page.
Hope that's useful...
Simon
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the replies.
More specific, I was basically looking for a Tag library which enables be to insert an HTML table in my jsp
something like, ....:table

Can anyone help me ?
Thanks
 
Joe Pardi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the grid tag at http://www.dotjonline.com/taglib/grid.jsp
The look and feel of the grid is customizable using pre-defined CSS styles.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to stick with Simon and say "HTML in tags is evil".
Rather than taking our word for it, it may be a process you have to go through yourself, but it's something I'm dead-set against.
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
I'm going to stick with Simon and say "HTML in tags is evil".
Rather than taking our word for it, it may be a process you have to go through yourself, but it's something I'm dead-set against.

I agree with you and Simon too, but there's something interesting about the future to point out: JSP 2.0, currently in public-draft phase, will support the development of tags using JSP itself. That is, you could generate a reusable whole-table tag by creating a "tag file" expressed in JSP instead of Java.
It might be fun to play with the current RI; I encourage everyone to try it out. The other major feature of JSP 2.0 is the expression language, drawn from JSTL 1.0.
 
Scott Duncan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you realy want to do it:
In doEndTag method of Tag:
pageContext.getOut.write("<table><tr><td>....</table>");

In JSP:
<prefix:table />
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!