[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2174
  • Last Modified:

Using Display Tag on a JSP page help

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
0
sonu19
Asked:
sonu19
  • 3
1 Solution
 
summerianCommented:
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) {
    while(rs.next()){
        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
        list.add(bean);            
    }
}
  
/*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" />
      
</display>

Open in new window

0
 
summerianCommented:
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" />
</display>

Open in new window

0
 
summerianCommented:
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">
    <display:column>
<%=((DynaBean)pageContext.getAttribute("myDynaBean")).get("columnName1")%>
    </display:column>
    <display:column>
<%=((DynaBean)pageContext.getAttribute("myDynaBean")).get("columnName2")%>
    </display:column>
 
</display>

Open in new window

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now