We help IT Professionals succeed at work.

Using Display Tag on a JSP page help

sonu19 asked
Hey Guys,

I am trying to create a jsp page I want to use DisplayTag Library to display results from my database table.
I might have 1,000,000 records and I want to display like 50 recordds first page then 50 on second so forth.

I am having a lot of trouble with DisplayTag Library.

I am new to java so can someone point me in a direction.

I can get the data from the table fine.

This is what I got on my page as far as DisplayTag is concerned.
What other referneces do I need? or beans?

RowSetDynaClass resultSet = new RowSetDynaClass(rs, false);
request.setAttribute("results", resultSet);

<display:table name="requestScope.results.rows" />

Thanks for all your response
Watch Question

No, you cannot instruct diaplay tag library to read data from ResultSet directly. It needs a List/array of beans , so that means you need to preprocess ResultSet (in your Struts action/Spring controller/other handling the request component) to create List/array of beans and then pass it to display tag library as you wrote.
/*Your java file*/
ResultSet rs;
//get ResultSet from database
List list = new ArrayList();
if (rs != null) {
        DataBean bean = new DataBean();//You need to create some data bean class and use it here
        d.setProperty1(rs.getString(1)); //set some String property you probably selected in SELECT sql clause
        d.setSygnKHidden(rs.getInt(2)); //the same for int
        //.. set all bean properties                
        //put bean into list
/*DataBean.java - just an example, rename class name and properties*/
public class DataBean{
   private String property1;
   private int property2;
   public String getProperty1(){
       return property1;
   public int getProperty2(){
       return property2;
   public void setProperty1(String p){
       property1 = p;
   public void setProperty2(int p){
       property2 = p;
<%-- Your JSP--%>   
<display:table id="row" name="dysp" pagesize="${__pagesize}">
    <!-- replace property1, property2 with actual properties-->
    <display:column property="property1" />
    <display:column property="property2" />

Open in new window

Sorry I did notice now that you use RowSetDynaClass. You can forget my previous post, but as long as display tag supports DynaBeans - don't know if it actually does... In that case use it like this:

<%-- Your JSP--%>   
<display:table name="requestScope.results.rows" pagesize="50">
    <display:column property="columnName1" />
    <display:column property="columnName2" />

Open in new window

In fact, display tag does not need to support DynaBeans - code below should work regardless (although is not pretty). As columnName1, columnName2 user column names from your SELECT clause.
<%-- Your JSP--%>   
<display:table name="requestScope.results.rows" pagesize="50" id="myDynaBean">

Open in new window

Explore More ContentExplore courses, solutions, and other research materials related to this topic.