Results 1 to 4 of 4
  1. #1
    sbmk is offline Member
    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Default Help !!! Dynamic Tabular List Generation !!!

    Hi all,
    I am new to Java. So, I need a little help.I am really sorry if I sound stupid.
    I want to generate/populate a dynamic table in JSP by fetching data from the database with the help of Servlets and other (non-JSP)Java files.
    Suppose, there are 3 columns in the table like product-id, name, order-date and the table grows/shrinks according to the data in the database.
    Can you give me an example showing what to do in the servlets/java files and also how to handle the pages when the data is huge,like, when you have to go to the next page to view all the data ? Thanks.
    -sb.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Help !!! Dynamic Tabular List Generation !!!

    Write the JDBC code to get the data and turn it into a List of some class that contains the data you want (this is your model).
    In your case it would have attributes for id, name, orderDate.
    The class containing this JDBC code is called your DataAccessObject (DAO). Its purpose is to get the data and return it in a form your application can use (eg the model).

    Once you have that working then write a servlet that calls this DAO.
    It will add the returned List to the request object and then forward to the JSP page.

    The JSP page can then get the List from the request and display it.
    There are tags that help with this, but I have no idea what level you are at, so can't make many suggestions.

    That's three steps.

    After that you can then worry about paging.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    sbmk is offline Member
    Join Date
    Oct 2012
    Posts
    3
    Rep Power
    0

    Default Re: Help !!! Dynamic Tabular List Generation !!!

    I tried to implement DAO as you had said.But, the problem still remains.I think the jsp page is creating the problem, but I am not really sure.

    I use Tomcat and Eclipse IDE. The java files are servlet.java, ProductDao.java, Products.java(getters/setters), MySQLConn.java(Database Connection file)
    and neither Tomcat nor Eclipse is showing any (java file related) errors. The jsp files are View.jsp & products.jsp.

    In View.jsp page we have the enter the product name and it will display the product name alongwith with its id and order date in products.jsp so that the

    user may know when a particular type of product (with its id) was ordered.

    Whenever I try to run this in IE 7, it gives errors like :-

    The method getProd_id() is undefined for the type ProductDao
    The method getName()() is undefined for the type ProductDao
    The method getOrdate() is undefined for the type ProductDao

    with other details and a huge Stacktrace.

    JSP CODE

    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,pkg.*,ss.*,java.util.*" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <%
    ProductDao pdview = (ProductDao)session.getAttribute("myDataList");
    if (pdview == null )
    {
    out.print("Object not found !!! ");
    }
    %>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Product Record</title>

    <SCRIPT langugae="JavaScript">

    function back()
    {
    form1.action="./View.jsp";
    form1.submit();
    }

    function forward() {
    form1.action="controller";
    form1.submit();
    }

    </script>

    <table width="800" border="1" align="left" cellpadding="2" cellspacing="1">
    <tr align="center" valign="middle" bgcolor="#999999">
    <td width="101"><span class="style22">Select</span></td>
    <td width="100"><font color="#000000" size="3" face="Times New Roman, Times, serif">Product Id</font></td>
    <td width="175"><font color="#000000" size="3" face="Times New Roman, Times, serif">Name</font></td>
    <td width="175"><font color="#000000" size="3" face="Times New Roman, Times, serif">Order Date</font></td>
    </tr>
    <tr align="center" valign="middle" >

    <c:forEach items="${myDataList}" var="products">
    <td width="50"><span class="style22"><input type = "radio" name= "r1" id="r1" ></span></td>
    <td width="50"><input name="orid" type="text" value="<%= pdview.getProd_id()%>" readonly="true"></td>
    <td width="100"><input name="ortp" type="text" value="<%= pdview.getName()%>" readonly="true"></td>
    <td width="100"><input name="orodt" type="text" value="<%= pdview.getOrdate()%>" readonly="true"></td>
    </c:forEach>
    </table>

    <div id="Layer8" style="position:absolute; width:434px; height:45px; z-index:4; left: 286px; top: 8px;">Product List:-</div>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <table width="200" border="1" align="center" cellpadding="2" cellspacing="1">
    <tr>
    <td width="40">Product ID:- </td>
    <td width="60%"></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <div id="Layer5" style="position:absolute; width:910px; height:30px; z-index:2; left: 25px; top: 280px;">
    <table width="89%" border="0" cellspacing="2" cellpadding="2">
    <tr align="center" valign="middle">
    <td width="62%"><input name="BUTTON" type="button" id="BUTTON" value=" BACK " onClick="back()"></td>
    <td width="38%"><input name="BUTTON" type="button" id="BUTTON" value=" MODIFY " onClick="forward()" ></td>
    </tr>
    </table>
    </div>
    </div>
    <p>&nbsp;</p>
    </form>
    <p>&nbsp;</p>
    </div>
    </body>
    </html>

    ERRORS !!!
    The method getProd_id() is undefined for the type ProductDao
    The method getName()() is undefined for the type ProductDao
    The method getOrdate() is undefined for the type ProductDao

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Help !!! Dynamic Tabular List Generation !!!

    A DAO is not a model object.
    It should not be appearing in your JSP page at all.

    There should be a Product model, which contains the data for product (and suitable getters and setters).

    What does your servlet look like?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Tabular Expression
    By dougie1809 in forum New To Java
    Replies: 11
    Last Post: 03-26-2012, 10:32 PM
  2. Dynamic Choice list AWT
    By Javasubbu in forum AWT / Swing
    Replies: 0
    Last Post: 11-21-2011, 09:08 AM
  3. Regarding Tabular data from .doc file
    By praveen83 in forum Advanced Java
    Replies: 10
    Last Post: 03-23-2010, 12:26 PM
  4. Dynamic List for Country and City
    By pinto_g in forum New To Java
    Replies: 2
    Last Post: 03-10-2010, 03:24 PM
  5. dynamic generation of tables
    By masa in forum AWT / Swing
    Replies: 1
    Last Post: 12-19-2008, 11:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •