Archive for December, 2008

A simple displaytag grid demo

Display tags are pretty good option when it comes to creating a enterprise class data grid.
The sample code given below is quite a head start for building up a bulky grid.

// Create class that returns a list
package org.ixfree.Displayags;
import java.util.*;
public class GridList {

private List aList;

public List getAList() {
return aList;
}
public void setAList(List list) {
aList = list;
}
public GridList(int i)
{
this.aList = new LinkedList<DataBean>();
}
}

// POJO bean that goes into the list. DataBean in our case.
package org.ixfree.Displayags;
public class DataBean {

private String name;
private String age;

public String getName()
{
return this.name;
}

public String getAge()
{
return this.age;
}

public String setName(String name)
{
this.name = name;
}

public String setAge(String age)
{
this.age = age;
}
}

// Get the libraries reffered
// Sql needed if you wanna get the data out of the table. Ofcourse there are much better ways to do it.
<%@ taglib uri=”http://displaytag.sf.net” prefix=”display”%>
<%@ page import=”java.util.*” %>
<%@ page import=”org.ixfree.Displayags.*” %>
<%@ page import=”java.sql.*” %>

<%
// Make a list of data for populating grid
List<DataBean> list = new GridList(6).getAList();

// .. Get the data into the bean and add it to the list.
// .. Every bean here refers to a row in the grid. Yeppiiie….

// Put the list in the request
request.setAttribute( “storedList”,list);
%>

// Make it as a XHTML (good for the browser)
<head>
<!– All script and style/references goes here –>

<link href=”ixfreeDemoDisplayTags.css” rel=”stylesheet” type=”text/css”>
</head>
<body>
<!– If you dont want the grid to introduce scroll bar for the window, but ok for the grid –>
<div id=”My_DisplayTag_Grid” style=”width: 800px; height: 360px; overflow: auto” >
<!–
The pageSize is pretty useful when you wanna have pagination
class is just our regular css stuff
headerClass applies to the TH’s

name attribute of the display:table tag does the magic of reading our list.

–>
<display:table name=”storedList” class=”myDisplayTagStyle” id=”displayTable” pagesize=”10″ requestURI=”theCurrentJspPage.jsp”>
<display:column  sortable=”true” property=”name” title=”Name”  class=”myDisplayTagStyle” headerClass=”myDisplayTagStyle”/>
<display:column  sortable=”true” property=”age” title=”Age” class=”myDisplayTagStyle” headerClass=”myDisplayTagStyle” />
</display:table>
</div>
</body>

### ixfreeDemoDisplayTags.css goes this way ###
html
{
scrollbar-base-color: #dddddd;

}

table.myDisplayTagStyle
{
background-color: #dddddd;
}

td.myDisplayTagStyle
{
border-color: black;
border-width: 1px 1px 1px 1px;
border-style: solid;
margin: 0;
font-family:Arial Verdana;
font-size:10pt;
overflow: auto;
white-space:nowrap;
padding-top: 6px;
padding-right: 6px;
padding-left: 6px;
padding-bottom: 6px;
}

tr.odd
{
border-color: black;
border-width: 1px 1px 1px 1px;
border-style: solid;
margin: 0;
padding: 4px;
background-color: #ffffff;
white-space:nowrap;
}

tr.even
{
border-color: black;
border-width: 1px 1px 1px 1px;
border-style: solid;
margin: 0;
padding: 4px;
background-color: #dddddd;
white-space:nowrap;
}

th.myDisplayTagStyle
{
background-color: #dddddd;
border-color: black;
border-width: 1px 1px 1px 1px;
border-style: solid;
font-size: 9pt;
white-space: nowrap;
padding-top: 10px;
padding-right: 10px;
padding-left: 10px;
padding-bottom: 10px;
}

Add comment December 11, 2008


Blogroll

Category Cloud

ajax books Education free software linux Market opensource open standards OSS programming search servers services Uncategorized web

Archives