?
Solved

How to create a data grid in JSP?

Posted on 2009-04-22
6
Medium Priority
?
1,176 Views
Last Modified: 2013-11-24
HI ALL,
i need to create a data grid to display my datatable. this data grid needs PAGING, sorting functionalities. could you guys help me with that? i am new to JSP/JAVA.

thanks a lot
my class:
public class TA_Transaction
{
  public Long id;
  public Long ta_InvestorAccId;
  public java.sql.Timestamp eff_date;
  public Double amount;
  public String send_email;
  
  public Long getTransId()
  {
    return id;
  }
  public Long getTransFromId()
  {
    return ta_InvestorAccId;
  }
  public java.sql.Timestamp getPaymentDate()
  {
    return eff_date;
  }
}
 
----------------------
my form:
<html>
<head>
</head>
<body>
<% 
  java.util.ArrayList transactions = new java.util.ArrayList ();
  java.util.Vector trans;
  TA_Transaction tran;
//GET all data from database
    com.sr.dblib.Db int_db;
    int_db = new com.sr.dblib.Db(com.sr.dblib.Db.INTRANET_DB);
    String QueryString = "SELECT * from TA_TRANSACTION where ID= 1039162";
    trans =  int_db.SelectObjs(QueryString,TA_Transaction.class);
    for(int i = 0; i < trans.size(); i++)
    {
      tran = (TA_Transaction) trans.get(i);
      transactions.add(tran);
    }
%>
<form id="main_form" name="main_form">
<table width="100%" cellpadding="0" cellspacing="0" id="formStripe" class="formTable">
         //  the transactions is always empty, i don't know what's going on, where should i put the code which is used to get transactions?
        <c:if test="${empty transactions}">
                <tr>
                  <td colspan="11">No data available</td>
                </tr>
              </c:if>
            <c:if test="${!empty transactions}">
              <tr class="formHeader">
                <td>TranID</td>
                <td>TransFrom</td>
                
              </tr>
//    var="TA_Transaction" : the value of "var " must be the defined class name? or i can use any name?      
              <c:forEach var="TA_Transaction" items="${transactions}">
                <tr>
                  <td><a href="my2ndPage.jsp?id=${TA_Transaction.id}">${TA_Transaction.id}</a></td>
                  <td>${TA_Transaction. eff_date}</td>
                  
                 </tr>
               </c:forEach>
             </c:if>
          </table>
// how to do paging and sorting in JSP? PLS HELP ME!!!!
</form>
</body>
</html>

Open in new window

0
Comment
Question by:viola123
  • 3
  • 2
6 Comments
 
LVL 28

Accepted Solution

by:
rrz earned 2000 total points
ID: 24211865
>//  the transactions is always empty, i don't know what's going on, where should i put the code which is used to get transactions?  

You have defined transactions as a scripting variable.
You could add the following line to the end of your scriptlet.
request.setAttribute("transactions", transactions);
%>
That will create a scoped variable that is available to JSTL.
Alternately, you could create a javabean to hold your db code.  

For paging, you could use third party tags or use JSTL.  See  
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/Q_24321162.html
0
 
LVL 28

Assisted Solution

by:rrz
rrz earned 2000 total points
ID: 24211900
I just noticed that the names of your methods.
>  public Long getTransId()
change that to
  public Long getId()
that way  
>${TA_Transaction.id}
will work.  Also  
>public java.sql.Timestamp getPaymentDate()
should be  
public java.sql.Timestamp getEff_date()
also
>${TA_Transaction. eff_date}
should be  
${TA_Transaction.eff_date}

Please research javabeans and follow the conventions. Life will be easier if you do.
0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24212088
use displaytags for this purpose . Its a simple library which provides sorting,paging functionality.

refer this url http://displaytag.sourceforge.net/1.2/

-Murali*
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Expert Comment

by:rrz
ID: 24215893
0
 
LVL 6

Author Comment

by:viola123
ID: 24222085
rrz@871311:
thanks a lot, i am doing paging now, to see if it works and let you know

thanks heaps
0
 
LVL 6

Author Comment

by:viola123
ID: 24257228
hi,
sorry to reply late, i was distracted by other stuff. i will post paging issue to another thread.
 thanks a lot
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question