Click here to Skip to main content
Click here to Skip to main content

Data Grid for JSP

By , 21 Jul 2006
 

Sample Image - DBGrid.png

Introduction

This article presents a Grid control very similar to the one found in ASP.NET, but for JSP pages. Although a data grid can be easily rendered using JSTL for loop tag, it tends to clutter the code and hence debugging can become very difficult. The control presented in this article makes coding such grids a breeze and also it helps one to keep the code clean.

Features at a glance

At present the control implements following things.

  • Data pagination.
  • Sorting by a specified column.
  • Automatic row number display.
  • Image based hyperlink columns.
  • Hyperlink columns.
  • Custom data formatting.
  • Value decoding.
  • Ability to bind to a List.
  • Ability to bind to a ResultSet.
  • Ability to bind to a RowSet.

Apart from this it also allows one to specify column names to be used while constructing the HREF element of the hyperlink. This reference then at runtime automatically gets substituted by the column value. For example the following code snippet

<grd:imagecolumn headerText="" width="5" HAlign="center" imageSrc="images/Edit.gif" 
    linkUrl="javascript:doEdit('{CLICORPORATION}', '{CLICLIENT}')" imageBorder="0" 
    imageWidth="16" imageHeight="16" alterText="Click to edit"></grd:imagecolumn>
results in following code to be outputted to the browser
<td WIDTH="5%" ALIGN="center">
    <a HREF="javascript:doEdit('TATA', 'TELCO')">
        <img SRC="images/Edit.gif" BORDER=0 WIDTH=16 HEIGHT=16 ALT="Click to edit">
    </a>
</td>

The Control Details

The DBGrid control consists of following sub controls (classes).

  1. gridpager - This control is responsible for rendering the pager control. This control has following attributes to customize the images displayed for navigation. All these attributes are mandetory attributes.
    • imgFirst - Custom image to be displayed for navigate to first page action.
    • imgPrevious - Custom image to be displayed for navigate to previous page action.
    • imgNext - Custom image to be displayed for navigate to next page action.
    • imgLast - Custom image to be displayed for navigate to last page action.

  2. gridsorter - This control is responsible for providing the sort support. The most important and required attributes for this control are:
    • sortColumn - The name of the column to be used while constructing ORDER BY clause.
    • sortAscending - The boolean value indicating whether to sort in ascending order or descending order.

    Apart from above two attributes this control has following two optional attributes to customize the images that appear in the column header to indicate the current sort order. If not specified the control assumes that ImgAsc.gif and ImgDesc.gif are present in the images folder.

    • imageAscending - Image to be displayed in header of the associated column when the data issorted in ascending order.
    • imageDescending - Image to be displayed in header of the associated column when the data is sorted in descending order.

  3. textColumn - This control is responsible for rendering the text column. The control has following special attributes to control the apperance of the rendered text.
    • maxLength - Controls the number of character to be outputted.

  4. dateColumn - This control is responsible for rendering the date time values. The control has following special attributes to control the apperance of the rendered text.
    • dataFormat - The format string as defined in java.text.DateFormat

  5. numberColumn - This control is responsible for rendering the numeric values. The control has following special attributes to control the apperance of the rendered text.
    • dataFormat - The format string as defined in java.text.DecimalFormat

  6. anchorColumn - This control is responsible for rendering the hyperlinks. This control also supports value substitution as explained in previous section. The control has following special attributes to control the apperance and behavior of the hyperlink.
    • linkText - A fixed string to be used to render the hyperlink. Alternatively one can also specify the column value to be used using dataField attribute
    • linkUrl - The url to be invoked when this link is clicked. This can also be a javascript function.
    • target - The name of the window or frame in which the referenced url is to be opened.

  7. imageColumn - This control is responsible for rendering the hyperlinked image. This control also supports value substitution as explained in previous section. The control has following special attributes to control the apperance and behavior of the hyperlink.
    • imageSrc - The image to be displayed.
    • imageWidth - The width of the image in pixels.
    • imageHeight - The height of the image in pixels.
    • imageBorder - The width of the image border in pixels.
    • alterText - The tooltip text to be displayed.
    • linkUrl - The url to be invoked when this link is clicked. This can also be a javascript function.
    • target - The name of the window or frame in which the referenced url is to be opened.

  8. rownumColumn - This control is responsible for numbering the rows displayed in the gird.

  9. decodeColumn - This control is responsible for decoding the column values and display the decoded text. The control has following special attributes to control the decoding.
    • decodeValues - A string containing values to be decoded seperated by the delimeter specified using valueSeperator attribute.
    • displayValues - A string containing values to be displayed seperated by the delimeter specified using valueSeperator attribute.
    • valueSeperator - The value delimeter.

DBGrid Control Container

The DBGrid control it self has following special properties.

  1. dataSource - Allows one to specify the java.sql.Connection object to be used to fetch the values from database or a java.util.List.
  2. dataMember - The SQL to be used to retrieve the required data. The SQL should not contain the ORDER BY clause. If you are specifying java.util.List for dataSource then this can be left blank.
  3. pageSize - The number of rows to be displayed in a page.
  4. currentPage - The page number to be displayed.

Using the code

following code snippet shows the DBGrid control usage. The same source can also found in the demo application.

<%@ taglib uri="/WEB-INF/tags/datagrid.tld" prefix="grd" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="com.freeware.gridtag.*" %> 
<%
int intCurr = 1;
int intSortOrd = 0;
String strTmp = null;
String strSQL = null;
String strSortCol = null;
String strSortOrd = "ASC";
boolean blnSortAsc = true; 
strSQL = "SELECT CLICORPORATION, CLICLIENT, CLIDESCRIPTION, " +
         "CLIENABLED, CLIUPDSTAMP FROM CLIENTMASTER "; 
Connection objCnn    = null;
Class      objDrvCls = null;
objDrvCls = Class.forName("oracle.jdbc.driver.OracleDriver");
objCnn = DriverManager.getConnection("jdbc:oracle:thin:@Host:port:sid", 
                                     "cashincpri", "cashincpri");
if (objDrvCls != null) objDrvCls = null;
strTmp = request.getParameter("txtCurr");
try
{
  if (strTmp != null)
  intCurr = Integer.parseInt(strTmp);
}
catch (NumberFormatException NFEx)
{
}
strSortCol = request.getParameter("txtSortCol");
strSortOrd = request.getParameter("txtSortAsc");
if (strSortCol == null) strSortCol = "CLICLIENT";
if (strSortOrd == null) strSortOrd = "ASC";
blnSortAsc = (strSortOrd.equals("ASC"));
%>
<html>
<head>
<title>Grid Tag Demonstration</title>
<link REL="StyleSheet" HREF="css/GridStyle.css">
<script LANGUAGE="javascript">
function doNavigate(pstrWhere, pintTot)
{
  var strTmp;
  var intPg; 
  strTmp = document.frmMain.txtCurr.value;
  intPg = parseInt(strTmp);
  if (isNaN(intPg)) intPg = 1; 
  if ((pstrWhere == 'F' || pstrWhere == 'P') && intPg == 1)
  {
    alert("You are already viewing first page!");
    return;
  }
  else if ((pstrWhere == 'N' || pstrWhere == 'L') && intPg == pintTot)
  {
    alert("You are already viewing last page!");
    return;
  }
  if (pstrWhere == 'F')
    intPg = 1;
  else if (pstrWhere == 'P')
    intPg = intPg - 1;
  else if (pstrWhere == 'N')
    intPg = intPg + 1;
  else if (pstrWhere == 'L')
    intPg = pintTot; 
  if (intPg < 1) intPg = 1;
  if (intPg > pintTot) intPg = pintTot;
  document.frmMain.txtCurr.value = intPg;
  document.frmMain.submit();
}
function doSort(pstrFld, pstrOrd)
{
  document.frmMain.txtSortCol.value = pstrFld;
  document.frmMain.txtSortAsc.value = pstrOrd;
  document.frmMain.submit();
}
</script>
</head>
<body>
<h2>Grid Example</h2>
<form NAME="frmMain" METHOD="post">
<grd:dbgrid id="tblStat" name="tblStat" width="100" pageSize="10" 
    currentPage="<%=intCurr%>" border="0" cellSpacing="1" cellPadding="2" 
    dataMember="<%=strSQL%>" dataSource="<%=objCnn%>" cssClass="gridTable">
 <grd:gridpager imgFirst="images/First.gif" imgPrevious="images/Previous.gif" 
      imgNext="images/Next.gif" imgLast="images/Last.gif"/>
 <grd:gridsorter sortColumn="<%=strSortCol%>" sortAscending="<%=blnSortAsc%>"/>
 <grd:rownumcolumn headerText="#" width="5" HAlign="right"/>
 <grd:imagecolumn headerText="" width="5" HAlign="center" 
      imageSrc="images/Edit.gif" 
      linkUrl="javascript:doEdit('{CLICORPORATION}', '{CLICLIENT}')" 
      imageBorder="0" imageWidth="16" imageHeight="16" 
      alterText="Click to edit"/>
 <grd:textcolumn dataField="CLICLIENT" headerText="Client" 
      width="10" sortable="true"/>
 <grd:textcolumn dataField="CLIDESCRIPTION" headerText="Description" 
      width="50" sortable="true"/>
 <grd:decodecolumn dataField="CLIENABLED" headerText="Enabled" width="10" 
      decodeValues="Y,N" displayValues="Yes,No" valueSeperator=","/>
 <grd:datecolumn dataField="CLIUPDSTAMP" headerText="Last Updated" 
      dataFormat="dd/MM/yyyy HH:mm:ss" width="20"/>
</grd:dbgrid>
<input TYPE="hidden" NAME="txtCurr" VALUE="<%=intCurr%>">
<input TYPE="hidden" NAME="txtSortCol" VALUE="<%=strSortCol%>">
<input TYPE="hidden" NAME="txtSortAsc" VALUE="<%=strSortOrd%>">
</form>
</body>
</html>
<%
try
{
    if (objCnn != null)
        objCnn.close();
}
catch (SQLException SQLExIgnore)
{
}
if (objCnn != null) objCnn = null;
%>

The attached demo zip file also contains the ddl and dml which you can directly use to create the necessary table and populate the test data. I have tested this control using oracle database and the jdbc thin driver. For other databases you may have to change the dml.

References

The links which helped me a lot in designing this control library,

History

  • July 27, 2004 - Initial release.
  • May 12, 2005 - Added support for List. DBGrid can now render data supplied as object list. Changed names of sourceSQL to dataMember and connection to dataSource. Updated sample application to demonstrate the same.
  • June 03, 2005 - Updated the sample code in article to reflect the changes made in last release.
  • January 10, 2006 - Added support for ResultSet and RowSet. Added new sample RawJDBCGrid.jsp page to demonstrate this. While supplying these types of object as dataSource care must be taken to make this ResultSet SCROLLABLE (ie. ResultSet.TYPE_SCROLL_INSENSITIVE).
  • April 07 2006 - Fixed the bug in page navigation. Credit goes to Member No. 2833981 for pointing out this bug.
  • July 22, 2006 - Small bug fix to allow multiple dbgrids on single page. All credit goes to to Dave Lilley for pointing out this bug as well as suggesting the solution.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

About the Author

Prasad Khandekar
Software Developer (Senior) Freelancer
India India
Member
I am a software professional with over 20 years of commercial business applications design and development experience.
 
My programming experience includes Java, Spring, .NET, Classic VB & ASP, Scripting, Power Builder, PHP, Magic & far far ago FoxPro, C, Assembly and COBOL.
 
From last 11 years I am mostly working with Java Technology. I am currently available to take up new assignments.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionPagination problem when i mention limit to select query in mysqlmemberskola221 Feb '13 - 6:01 
Hai Parsad Khandekar,
I am using this Data grid. It is very attractive. but I have small concern please solve my issue.
 
Iam using MySql database when i pass the select query .It show all possible records with pagination.But as per my requirement i need first 150 records so I set the limit 150 to Query.At this time Records are not shown in datagrid but pagination is done for all Possible records .Here not taking the limit.When I select page from Drop down list or next button after 150 th record onwords it showing empty rows in datagrid. So please do need full for me..
 
Thanks & Regards,
Santosh Kumar Kola
AnswerRe: Pagination problem when i mention limit to select query in mysqlmemberPrasad Khandekar3 Mar '13 - 10:44 
Hello,
 
Thank's a lot for finding this control useful. The grid control can take List as it's input. What you can do is to create the list by yourself and call the setTotalRecords with value as the size of the list. The grid will show the records correctly.
 
If you are specifying the Connection and SQL then the control generates count query internally by appending substring after FROM keyword of your specified query to "SELECT COUNT(1)". I feel this query should also return correct count 150 in this case assuming there are more than 150 records in the table.
 
regards,
Prasad P. Khandekar
Knowledge exists, man only discovers it.

QuestionList of objectsmemberblack_cat_lhh21 Mar '11 - 1:28 
Hi,
 
If I store objects in List then what in tag dataField="???" ...>....
 
Thanhks
AnswerRe: List of objectsmemberPrasad Khandekar3 Mar '13 - 10:46 
For object list the dataField should contain the name of the getter method without get prefix.
Prasad P. Khandekar
Knowledge exists, man only discovers it.

GeneralExport to Excel and PDFmembervsuriyaprakash15 Feb '11 - 22:17 
Can you please tell me how to export datagrid data to excel and pdf?
QuestionHow to conditionally test the dataField within the dbGrid?memberMatilda Fabunmi5 Aug '10 - 5:57 
Can rows be color coded based on values of a dataField and how do you capture and conditionally test the dataField within the dbGrid?
 
Thanks
Matilda

GeneralDifferent image in same columnmembermanishipra25 May '10 - 21:41 
Hi,
 
I need to display different images in same column.
I have done the following thing for that.
I am using List as datasource. My list contains objects of a class. In my class there is status attribute and imageURL. On the basis of status I getImageURL() method returns the a string of image url. But when I use imageURL as imageSrc. Find below code

 
But when my I access the page I get following error on server console
 
There is no Action mapped for namespace / and action name imageUrl. - [unknown location]
 
I am using struts2 and Weblogic.
GeneralBind image coulumn with datafieldmembermanishipra25 May '10 - 19:10 
Hi All,
 
Please tell me how can I bind the image column in the dbgid with datafield(images changes according to the values saved in database table)
 

Thanks
Manish
Generalcolumn resizing using mousememberDigvijayj11 May '10 - 20:43 
Is it possible to rearrange size of columns of result page using mouse
GeneralPackage org.apache.tools.ant.* does not existmemberThayhor4 Mar '10 - 1:25 
I tried to implement the datagrid in my netbeans project. Initially I was getting package org.apache.tools.ant.* does not exist in com.freeware.anttasks package of ManifestReader class. I later remove this class from the source and now am getting exception in apache java.lang.RuntimeException: Uncompilable source code com.freeware.gridtag.GridSorter.doEndTag(GridSorter.java:94).... What can I do to solve this error and make the datagrid run properly. If the problem is from source compile error, how can I compile the source.
 
Thank you.
 
Thayhor
GeneralRe: Package org.apache.tools.ant.* does not existmemberThayhor5 Mar '10 - 2:31 
It has been resolved. Thank you.
GeneralProblem in Executingmemberdeveloper_nj2 Jan '10 - 21:34 
I have set up the code in Eclipse. And it is not showing any error but I am not able to Run the program. How do I execute this code.
QuestionCan I print data from datagridmembergateshahaji26 Dec '09 - 2:20 
I want to print whole data from datagrid. Is it possible? Plz give me solution.
I want print it like report.
QuestionCan I edit values into the gridmembervishaldsh8 Dec '09 - 21:23 
Please help me if i can edit the grid directly.
QuestionHow to use GridmemberHitha.M7 Oct '09 - 6:10 
Hello experts,
I am a new person to java!!!!!
Can anyone please tell me how to use this grid in jsp or servlet
I dont know anything about this
If any material to understand how to use this will be helpfull.
If possible please send it to my email id-hithujeevu@gmail.com
 
Thank You in Advance
Now i am Frown | :( s
I hope your answer makes me Smile | :)
Generaldata grid in jspmembernishi00715 Sep '09 - 0:25 
hi,
my problem is as follows:
i have a database in mysql as professor.
in this database i have 2 tables :
1)professor
2)student
professor table contains following fields:
1)professorid
2)firstName
3)lastName
4)email.
student table contains following fields:
1)studentid
2)firstName
3)lastName
4)email.
 
now i have to delete the records from the professor and student table
with the help of jsp file.
i want to create a datagrid in jsp file which will retrieve all the records of student from the student table.
now this datagrid should display the record from the student tabel as follows:
studentid firstName lastName email
1 aa aaa aa@gmail.com Delete
2 bb bbb bb@gmail.com Delete
where Delete is a button.
when user selects any one of the Delete button,
the record should be deleted from the datagrid and database also.
it should reflect the changes in datagrid.
if anyone can help me please send me the code.
please also write the proper comments so that it will be easy to understand the code.
thanks and regards
nishi kishore
Generalstore value in a string variable of a "dataField" of grd:textcolumn tagmemberdhiman debnath12 Aug '09 - 1:08 
Hi,
I have facing a problem while using this datagrid.
Suppose i have used
<grd:textcolumn:textcolumn dataField="poolId" headerText="Pool Id" width="30" sortable="true"></grd:textcolumn>
If i want to set the value of poolId in a variable and want to compare that value, how can i do it?
Please help..
 
Thanks
Dhiman
 
dhiman debnath

GeneralRe: store value in a string variable of a "dataField" of grd:textcolumn tagmemberGauraav26 Jan '10 - 8:18 
I am having the exact same problem!!!!
any help would be appreciated.
QuestionHow to edit the data of a specific row?membermaheswari panda9 Aug '09 - 19:20 
Can anyone tell me how to edit a record of this data grid? Please reply me.I need it its very urgent....
 
Thanks
GeneralAnchorColumn How to use dataField as linkTextmemberSubhashK26 Jun '09 - 1:21 
AnchorColumn How to use dataField as linkText
QuestionIs it possible to use radio button?membernsg8617 Jun '09 - 2:26 
is it possible to use radio button inside this
data grid..?
 
i would like to onclick the radio button which will bind the respective data
to a textbox..
 
by the way..the code work wonders..thanks alot..
GeneralRun time errormemberalmasoudi8 Jun '09 - 17:33 
Hello,
Please Help
I get an error "java.lang.NullPointerException"
Could i get updated dbgrid.jar file coz i think there is a diffrence in my DBGrid.class that i have and i don't know how to decompile it and correct it and compile it again in the jar file.. so i think it better to get the updated dbgrid.jar.
GeneralAnchorColumn and dataFieldmemberdvillecco15 May '09 - 7:24 
Got the following:
 

 
This column shows the text {realTeam1} in all rows. I want to display the content of the realTeam1 item from my List.
 
What is wrong?
 

Thanks in advance.
GeneralRe: AnchorColumn and dataField [modified]memberramyaintergy19 May '09 - 14:09 
Hi There,
 
I ran into the same issue. You are doing it right but the "linktext" property and imageSrc property do not resolve data field value they only accept plain text. I have fixed the code and built a new jar to resolve this issue please provide your email address I can send the jar if required.
 
Thanks for Mr.Prasad for a wonderful grid control and source code. Helped me to customize easily. Hope you don't mind me providing customized jar.
 
Thanks,
Ramya
 
modified on Tuesday, May 19, 2009 8:15 PM

GeneralRe: AnchorColumn and dataFieldmemberSubhashK26 Jun '09 - 1:19 
I have same problem please send me the jar file on this email id :
skatakdhond@gmail.com
GeneralRe: AnchorColumn and dataFieldmembermanishipra25 May '10 - 19:14 
I have the same problem ,I am not able to bind Anchor text with datafield
 
please send me the solution
 

Thanks
Manish
GeneralUpdating/Getting Handle to the Fieldsmemberbmeksava10 May '09 - 21:13 
I am trying to figure out how i can get a handle to the fields. For example, I want to do update the data. How would I be able to edit the data and then do updates against them.
 
Thanks,
 
Boon
QuestionAny licensing issues ?memberprabhjit singh deol27 Apr '09 - 18:54 
Hi Prasad,
 
The tool looks great. Just wanted to know if it would be OK to use this code and the associated jar files in commercial applications? Are there any legal/licensing/GPL issues ? Is there any kind of licensing at all associated with this?
 
Regards
PSD
AnswerRe: Any licensing issues ?memberPrasad Khandekar6 Jun '09 - 23:28 
Hello Prabhjit ,
 
You can use the code in commercial applications without any problem. The code is totally free. The DBGrid code does not fall under GPL.
 
Regards,
 
Prasad P. Khandekar
Knowledge exists, man only discovers it.

Questioncan u tell me how to use it ??memberbassoom19 Mar '09 - 2:51 
can you tell me how to use it ??
what are the configurations must be done at first??
GeneralCheckBox Column in JSP DataGrid.memberlucianodev43 Feb '09 - 14:27 
have to implement CheckBox Column in JSP DataGrid?
 
have new version ?
QuestionHow does the doEdit function work?memberrajesh_css6 Jan '09 - 15:34 
can anyone help me ,how the doEdit function works and what are the parameters passed in.......
 
Regards
Raj
GeneralDbGridmemberMember 415987126 Aug '08 - 0:04 
As I am new for java developement and read this code, Finally I try to implement this code and got success also.
 
Only one problem I am facing that the alterText on Image Column is not working.
 
<grd:imagecolumn headerText="" width="5" HAlign="center" imageSrc="images/Edit.gif"
linkUrl="javascript:doEdit('{CLICORPORATION}', '{CLICLIENT}')" imageBorder="0"
imageWidth="16" imageHeight="16" alterText="Click to edit"></grd:imagecolumn>
 

Can some one help me why the tool tips is not showing...
 
Regards
Smile | :)
GeneralCheckBox Column In JSP DataGridmemberamnahi30 Jun '08 - 3:05 
Hi,
 
I have to implement CheckBox Column in JSP DataGrid.
Anyone knowing solution please do reply.
 
Thanks in advance.
 
Aman
QuestionHow can get Pagination with Numbers(1 2 3 4 5 6 7 8 9 10 Next)memberashokadcrl12 Jun '08 - 1:36 
Hi All,
 
How can I get the Pagination with Numbers(1 2 3 4 5 6 7 8 9 10 Next) instead of First,Prvious,Next,Last.
 
Can anyone help to get the pagination in above format.
 
Thanks
Generali am not able to use this grid in my applicationmemberrenjithpaul18 Apr '08 - 0:08 
sir,
i am nw to jsp and java .I am in very much need of a data grid like this, but i cant implement it in my application.. sir please give me step by step implementation of this grid.. i had reffered to the previous post but im getting some error when i did it like that..
org.apache.jasper.JasperException: File "/WEB-INF/datagrid.tld" not found
 
plzz help me...
GeneralRe: i am not able to use this grid in my applicationmemberniket_shah8330 Apr '09 - 0:23 
This tld File is in config folder
so please put this config folders file in to your web-inf folder
its work then
QuestionNumer field not showingmemberBisweswar26 Dec '07 - 19:40 
I had put the codes as per need, and it works fine.
But Unfortunately the fields of type Number/Int not being shown in grid.
 
Please fix the error and give the solution immeditely.
 
Thanking you,
Bisweswar
AnswerRe: Numer field not showingmemberJMVillaG3 Apr '08 - 9:50 
Number Field are showing correctly. Poke tongue | ;-P
But you must include the dataFormat property to the column.
ex.
To know about format, visit :
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html

QuestionCan I insert and update values into the gridmemberMember 31100629 Dec '07 - 21:08 
Hi,
 
Is it possible to enter values and update them in the grid? If so can anyone give me a sample of the code
 
Regards
Anil
Questionhow to use listmembersumouser13 Nov '07 - 23:00 
Dear sir,
 
Grid for java is really a great job and it will help us (the developers) a lot.
I want to use it in my college project where i am presenting information in form of table. the scenario is that I am getting value from data base using bean method which returns List. the List contains Array of string.
Now I want to use your grid to show the data in tabular format. but i am facing problem. in fact i am not how to use the list. When i go through the queries related to it i found a reply by you in this regard that is
 
The request attribute named 'DATALIST' stores a reference to pojo List.
In case of pojos the attribute 'dataField' of any grid column holds the name of the getter method excluding the prefix 'get'.
e.g. If you hava a getter method named 'getDescription' coded for your pojo then specify value 'Description' in 'dataField' attribute of the grid column.
 
In this reply you have metioned pojo List. Can you help me to understand pojo list. what it is or how can i create a pojo list. if you provie any link in this regard it will help a lot.
 
Plz help me.
 
waiting for your valuable information
 

Thanks
 
sumouser
 
sumouser
Generalgenerating rows using JSPmemberlamarjones7 Sep '07 - 4:06 
I have tried using jsp code to generate the
GeneralRe: generating rows using JSPmemberiren1 Apr '08 - 6:19 
Hai friend send me generating rows using JSP code plz..
QuestionIs Multiple Grid Code available?membernyy_28 Aug '07 - 5:27 
Hello - Is Dave Lilley's code for displaying multiple grids on a page available? It wasn't in the download project or demo. I figured I would ask before I reinvent the wheel and do it myself. Thanks!
GeneralPrinting grid data..membertwinvaibhav6 Aug '07 - 0:32 
Hey
hi
 
i tried to print the grid data...but no success
pls is ther any solution???

 
There's never a Wronge Time To Do The Right Thing !!

GeneralRe: Printing grid data..membervishaldsh8 Dec '09 - 21:25 
What error you are getting
GeneralRe: Printing grid data..membertwinvaibhav9 Dec '09 - 1:05 
vishaldsh,
 
Thanks for your reply..although I dont remember what was the error as I had posted this problem way back in 2007... Big Grin | :-D
 
There's never a Wronge Time To Do The Right Thing !!

Questionsecurity alert popup.membertechmalli25 Jul '07 - 7:39 
Hi, when i am scrolling the mouse in the data grid, i am getting a security alert popup. This is in https env. works fine in http env. Any issues in the css?
 
can anyone help on this?

GeneralGive and take, I talk about my edit, you tell me your thoughts on printing....memberlamarjones25 Jul '07 - 3:48 

 
you can see there are things in the 'doedit' fields, these are strictly to tell me what row number and column number I am on. by clicking on any of the fields it will send that particular string back to the rendering class. How?
 
These tag library variables work as setters and getters, google what that means. But basically, add a variable to the .tld file, and then you got to make a setter and getter function wherever the rendering is going on, I put it in DBGrid.java.
 
So I added
 

editAction
true
true
java.lang.String


editBoolean
true
true
java.lang.Boolean

 
to the tld file, and then
 
/**
* Sets editAction.
*
*/
public String getEditAction()
{
return this.mstrEditAction;
}
/**
* Sets editAction.
*
*/
public boolean getEditBoolean()
{
return this.mstrEditBoolean;
}
 
along witht he get functions as well. This is passed in by stating in the call to the dbgrid tag library when trying to render it.
 

 

Now, depending on what type of value is being retrieved, you basically trap these statements in either the text column, image column, number column classes and so forth. Here is an example of what I did on my text columns.
 
private void setFlags() throws JspException
{
isRowEdit=false;
isCellEdit=false;
isEditAction=false;
editRow=-1;
editCol=-1;

try {
 
objTmp = (DBGrid) getParent();
rowNum=objTmp.rowNum;
colNum=objTmp.colNum;
editAction=objTmp.getEditAction();
if (editAction.indexOf("rowNum=")>-1){
isEditAction=true;
isRowEdit=true;
editRow=Integer.parseInt(editAction.substring(7));
}

if (editAction.indexOf("mouseClick=")>-1){
isEditAction=true;
isCellEdit=true;
editRow=Integer.parseInt(editAction.substring(11,editAction.indexOf("|")));
editCol=Integer.parseInt(editAction.substring(editAction.indexOf("|")+1));
}
} catch (Exception e) {
throw new JspException(e.getMessage());
}
}
 

 
That is actually called early in render detail, this snippet is done later on.
 
try
{
objBuf = new StringBuffer();
objBuf.append(" 0)
objBuf.append(" WIDTH=\"" + this.mintWidth + "%\"");
if (this.mintHeight > 0)
objBuf.append(" HEIGHT=\"" + this.mintHeight + "\"");
if (this.mstrCssClass != null)
objBuf.append(" CLASS=\"" + this.mstrCssClass + "\"");
else
objBuf.append(" CLASS=\"gridColumn\"");
if (this.mstrHAlign != null)
objBuf.append(" ALIGN=\"" + this.mstrHAlign.toLowerCase() + "\"");
if (this.mstrVAlign != null)
objBuf.append(" VALIGN=\"" + this.mstrVAlign.toLowerCase() + "\"");
 
if (this.mstrBgColor != null)
objBuf.append(" BGCOLOR=\"" + this.mstrBgColor + "\"");
if (this.mstrForeColor != null)
objBuf.append(" COLOR=\"" + this.mstrForeColor + "\"");
 

objBuf.append(">");
if (isEditAction){
if (rowNum==editRow){
if ((editCol==colNum)){
//block for single cell to be edited
strVal = formatField(pobjValue, this.mstrDataFormat);
if (strVal != null && this.mintMaxLength > 0)
if (strVal.length() > this.mintMaxLength)
strVal = strVal.substring(0, this.mintMaxLength) + "...";


objBuf.append("<input type=\"text\" name=\"field"+colNum+"\" value='"+strVal+"'>");
objBuf.append("</input>
");
} else if (editCol==-1) {
//block for whole row to be edited
strVal = formatField(pobjValue, this.mstrDataFormat);
if (strVal != null && this.mintMaxLength > 0)
if (strVal.length() > this.mintMaxLength)
strVal = strVal.substring(0, this.mintMaxLength) + "...";


objBuf.append("<input type=\"text\" name=\"field"+colNum+"\" value='"+strVal+"'>");
objBuf.append("</input>");
} else
{
//non edited rows when edit requested
strVal = formatField(pobjValue, this.mstrDataFormat);
if (strVal != null && this.mintMaxLength > 0)
if (strVal.length() > this.mintMaxLength)
strVal = strVal.substring(0, this.mintMaxLength) + "...";
objBuf.append(strVal);
}
} else {
objBuf.append("");
strVal = formatField(pobjValue, this.mstrDataFormat);
if (strVal != null && this.mintMaxLength > 0)
if (strVal.length() > this.mintMaxLength)
strVal = strVal.substring(0, this.mintMaxLength) + "...";
objBuf.append(strVal);
objBuf.append("
");
}

}else {

objBuf.append("");
strVal = formatField(pobjValue, this.mstrDataFormat);
if (strVal != null && this.mintMaxLength > 0)
if (strVal.length() > this.mintMaxLength)
strVal = strVal.substring(0, this.mintMaxLength) + "...";
objBuf.append(strVal);
objBuf.append("
");
}
 
// Write created HTML to output stream.
this.pageContext.getOut().print(objBuf.toString());
}
 

Ok, that should suffice for now. Figure out the rest (notice that I am getting a jsp datepopup to come out for the date columns?) as I am not fielding questions on this.
 
But someone tell me how to print this in specfic formats!!
 


 
lamarjones@nc.rr.com
Ok, what I want to do is to print this data sheet, how would you recommend I do that?
 
In exchange, I'll talk about my editing procedure. I have done a couple of things, none great but pretty cool.
 
I got to a point where my rows look like this.
 
<img SRC="images/Edit.gif" WIDTH=16 HEIGHT=16 BORDER=0 ALTER="null">06/07/2000 00:0001/01/1960 01:2201/01/1960 01:42T - 173,973.36 Sq. Ft. Charles Harris 3rd - 2200 - 0600
Generala request from johnson josephadminSean Ewington23 Jul '07 - 4:18 
"i am not able to configure this demo project...actually i changed database from oracle to mysql...and i put this all application into my context path...so which URL i have to type in my address bar for accessing this application...let me know your suggections... context path "
- johnson joseph

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 21 Jul 2006
Article Copyright 2004 by Prasad Khandekar
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid