• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

paging and sorting

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi;

from controller i will get names to jsppage; these names come as ArrayList; For e.g names are

"aaaa"
"bbbbbbbb"
"ccccccccc"
"dddddddddd"
"eeeeeee"
"fffffffff"

i want to implement paging concept for these names and also sorting;


NAME

"aaaa"
"bbbbbbbb"
"ccccccccc"
"dddddddddd"
"eeeeeee"
"fffffffff"

i am using displaytaglib;i have seen the examples source code;but i didnt understand how to apply to my code;should i write bean class for this or else only my existing jsp is enough;

<display:table list=".." sort="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" />
</display:table>

what should i put in list parameter;how will i get that;how to get the property="name";please anybody write some sample code;
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi kesav

Again Struck with the same thing


see your Arraylist which is coming in request parameter from some class or may be coming through bean .If you are trying to get it through bean your bean should have this thing



public class personal
{
getter and setter of name
}

and the class where you are getting data should be like this

ArrayList arr = new ArayList();
for(i=1;i<=length of the data;i++)
{
personal per = new personal();
personal.setName("aaa");
arr.add(personal)
}
request.setattribute("list",arr);

Now in your jsp

Arraylist list = (ArrayList)request.getattribute("list");
pagecontext.setattreibute("list",list)

now use your display tag code but put "list" in nmae atribute of display:table

can u tell are you using the struts framework ?

Best Regards
Pankaj
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj,

thank u for ur response;i am waiting for ur response only;please bear with me;i am not using struts;

i have created a class;

package example;


public class Player
{

private String name;

public String getName()
{

return this.name;
}

public void setName(String name)
{

this.name= name;
}

}

and my controller;

package example;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Controller extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config) throws ServletException
{
super.init(config);
}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

ArrayList arr = new ArrayList();
Player per = new Player();
for(int i=1;i<=6;i++)
{

per.setName("aaa");
per.setName("bbb");
per.setName("cccc");
per.setName("dddd");
per.setName("eeee");
per.setName("fff");
arr.add(per);
}
request.setAttribute("list",per);

System.out.println(".........."+request.getAttribute("list"));
getServletContext().getRequestDispatcher("TAG.jsp").forward(request,response);

}
}

u have written na length of the data ;from where it will come;

TAG.jsp

<%@ include file="init.jsp" %>

<%@ page import="java.util.*"%>



<%
if(request.getAttribute("list") != null)
{
ArrayList list = (ArrayList)request.getAttribute("list");
request.setAttribute("list",list);

}

%>


<form name="frm" action="example/Controller">




<display:table name="list" sort="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" sortable="true"/>
</display:table>

when i run classcast exception is coming;

bye'
chaitanya
[ June 24, 2004: Message edited by: kesava chaitanya ]
 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList arr = new ArrayList();
Player per = new Player();
Hi kesava
The problem exists here


for(int i=1;i<=6;i++)
{

per.setName("aaa");
per.setName("bbb");
per.setName("cccc");
per.setName("dddd");
per.setName("eeee");
per.setName("fff");
arr.add(per);
}

it should br like this
arr["aa","bb","cc","dd","ee","ff"]

for(int i=0;i<6;i++)
{
Player per = new Player();
per.setName(arr[i]);
arr.add(per);
}

now try

But tell me are you using struts framework if not then how you are using taglibs

Best Regards
Pankaj
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj,

i changed the controller like this;

package example;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Controller extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config) throws ServletException
{
super.init(config);

}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

ArrayList arr = new ArrayList();
Player per = new Player();
String array[]= {"aa","bb","cc","dd","ee","ff"};

for(int i=1;i<=arr.size();i++)
{

per.setName(array[i]);
arr.add(per);
}
request.setAttribute("list",per);

System.out.println("......242...."+request.getAttribute("list"));
getServletContext().getRequestDispatcher("TAG.jsp").forward(request,response);

}
}

my TAG.jsp

<%@ include file="init.jsp" %>

<%@ page import="java.util.*"%>



<%
if(request.getAttribute("list") != null)
{
ArrayList list = (ArrayList)request.getAttribute("list");
request.setAttribute("list",list);

}

%>


<display:table name="list" sort="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" sortable="true"/>
</display:table>


can i put form tag in this TAG.jsp

like <form name="" action="example/Controller">
i will put submit button here in this jsp;when i click button it will call controller and come back to this jsp with the data;
when i run TAG.jsp


One item found.1

NAME



no items r coming here in paging;

u asked abt how ur using taglibs

in init.jsp

<%@ taglib uri="/WEB-INF/displaytag-11.tld" prefix="display" %>
<%@ page import="org.displaytag.sample.*, java.util.*,
org.displaytag.tags.TableTag,example.*"%>

i put tld file in WEB-INF and set that tld file in web.xml and also i put jars in classpath;
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in TAG.jsp

<%
if(request.getAttribute("list") != null)
{

ArrayList list = (ArrayList)request.getAttribute("list");
request.setAttribute("list",list);

}


%>
<display:table name="list" sort="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" sortable="true"/>
</display:table>

ArrayList list = (ArrayList)request.getAttribute("list");

on this line

java.lang.ClassCastException: example.Player
void _TAG._jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
[TAG.jsp]
TAG.jsp:10

is coming;what is the problem

when i changed the code like this;

<%
//if(request.getAttribute("list") != null)
//{
Object list1 = request.getAttribute("list");
request.setAttribute("list",list);

//}

%>

only one record is displaying i.e ff;

bye

chaitanya
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj,

i am able to display the records ;but when click next button page not found is coming;


controller

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{



String array[]= {"aa","bb","cc","dd","ee","ff"};

for(int i=0;i<array.length;i++)
{
Player per= new Player();
per.setName(array[i]);
arr.add(per);
}

request.setAttribute("list",arr);
getServletContext().getRequestDispatcher("TAG.jsp").forward(request,response);

}

TAG.jsp

<%@ include file="init.jsp" %>

<%@ page import="java.util.*"%>



<%
ArrayList list = (ArrayList)session.getAttribute("list");
%>






<display:table name="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" sortable="true"/>
</display:table>



sorting is also not working;

bye
chaitanya
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj

i solved the problem atlast;when u dont brain correctly these problems will come;anyways thank u for ur help ;


bye
chaitanya
 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI kesava

It is good that you have solved the problem but do paste the code here and tell what was the error in code written by me.

Best Regards
Pankaj
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj,

thank u for ur response;

this is JSP code;

<%@ include file="init.jsp" %>

<%@ page import="java.util.*,example.Player"%>

<%

ArrayList arr = new ArrayList();
String array[]= {"aa","bb","cc","dd","ee","ff"};

for(int i=0;i<array.length;i++)
{
Player per= new Player();
per.setName(array[i]);
arr.add(per);
}

request.setAttribute("list",arr);

%>

<display:table name="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" sortable="true"/>
</display:table>

if the whole code in in single jsp this is working fine;

but when write this code in controller;my controller is

package example;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.ArrayList;

public class Controller extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
ArrayList arr = new ArrayList();

public void init(ServletConfig config) throws ServletException
{
super.init(config);

}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{

HttpSession session = request.getSession();

String array[]= {"aa","bb","cc","dd","ee","ff"};

for(int i=0;i<array.length;i++)
{
Player per= new Player();
per.setName(array[i]);
arr.add(per);
}

session.setAttribute("list",arr);

System.out.println("in controller =="+session.getAttribute("list"));
getServletContext().getRequestDispatcher("/TAG.jsp").forward(request,response);

}
}

this servlet is in example package the jsp is not in example package now my jsp code is

<%@ include file="init.jsp" %>

<%@ page import="java.util.*,example.Player"%>

<%

ArrayList list=(ArrayList) session.getAttribute("list");
%>

<display:table name="list" pagesize="5" id="table1">
<display:column property="name" title="NAME" sortable="true"/>
</display:table>

first 5 records r coming properly but when i click next or sorting page not found is displayed.

i found the problem but i am way of solving the problem;

first time when u see the properties the path is
http://192.168.68.214:9000/example/Controller

on next the hyperlink the path is

http://192.168.68.214:9000/example/TAG.jsp?d-2449-p=2;

thats why its coming error;did u faced this error;

bye
chaitanya
 
Pankaj Narang
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI kesava

I think you are missing the requesturi attribute in display:table it should be somthing like this

requestURI="example/controller" in your display:table tag

Try this

I think thsi will do it

Best Regards
Pankaj
 
kesava chaitanya
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj,

when u put the objects in session i think this will enough;

<display:table name="sessionScope.list" pagesize="5" id="table1">

when u put objects in request what u said is correct;

am i correct or not?

anyway thank u for ur help and support;without i wouldn't have completed this application.do u know any other forums for java,JSP,xml,DOM;


bye
chaitanya
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also take a look at valuelist.sf.net
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic