How can I generate a dynamic HTML table using custom tags?

Discussions

Web tier: servlets, JSP, Web frameworks: How can I generate a dynamic HTML table using custom tags?

  1. I want to create a dynamic html table on my JSP page. I think usage of custom tags is the best idea for implementing this.
    Does anyone know of any resources where I could get some sample code for this?
    If anyone has done something similar before, then I would be grateful if you could share your code or give me some ideas.
    The situation is as follows: My JavaBeans will get data from the EJB´s as a "vector of objects". I would like to now display each object with its attributes in one row and so on (i.e. OrderID, Price, Quantity etc). I am confused as to how I should implement it.
    Is it possible that my custom tag can create an instance of the JavaBean and use the values directly from the JavaBean?

    Any help in this regard would be appreciated. Even a small sample "simple" code would help. Thanks!
    Sanjit
  2. here is a very simple ex:

    JSP Page

    <%@ taglib uri="/META-INF/taglib.tld" prefix="html" %>
    <html:GenerateTable/>

    TLD File

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems...
    <taglib>
      <tlibversion>1.0</tlibversion>
      <jspversion>1.1</jspversion>
      <tag>
        <name>GenerateTable</name>
        <tagclass>TagHandler.class</tagclass>
        <bodycontent>empty</bodycontent>
      </tag>
    </taglib>

    TagHandler class

    public int doStartTag() throws JspException {
      //get JspWriter
      JspWriter out = pageContext.getOut();

      //lookup EJB and get your Vector of data

      out.println("<table>");
          //iterate thru Vector and write html table rows
      out.println("</table>");
     
      return SKIP_BODY;
    }