File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Displaying N rows per page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying N rows per page" Watch "Displaying N rows per page" New topic
Author

Displaying N rows per page

N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Hi all... I am using Struts and JSP for a project. I want to display a fixed no. of rows (retrieved from database) in a page. Can anyone please help me ? Its an urgency.

Thank u all in advance...


Regards<br />--<br />Niranjan Nanda<br />Consultant<br />Capgemini Consulting India <br />Mumbai<br />Phone: 9324951476
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
Hi nanda

I think you asking the same question second time , if you are using struts and jsp their are may ways to solve your proble,

If i am not wrong you might be getting a vector or arraylist of objects in your jsp and you want to display them in pages ,

you can use a additional taglibrary known as display taglib , if you want to use this you can search for tutorials on web ,or if decided tell i will sen you some example of this tag library,

their are many other options of doing the paging like using pager taglibrary or usting JSTL taglibrary their are many options

Best Regards
Pankaj
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Hello Pankaj....

I am extremely sorry if my question annoyed you. yes i m asking this question for 2nd time, but earlier i asked it in JSP room. Because i am using struts, hence i asked it again in this room. anyway, i have downloaded the displaytag but not getting those properly. kindly send some tutorial (with code if possible). thank you.
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi nanada

--------------------------------------------------------------------------------
http://www.displaytag.org/example-paging.jsp

you can use this tutorial , this is the best example for displaytaglib

if any further problem comes you can post it here

Best Regards
Pankaj
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Hello Mr. Pankaj... thank you, but i have that tutorial earlier, but can't understand it properly. can you please explain the displaytag's functionality..

thank u in advance..
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi nanda

ok lets go step by step

1: if you are using struts that mean all the logic is there in your action classes,

ok lets take an example where i will get the users which are deactivated in a discussion forum,

Wat i did in my action class is retrieved the data from datbases which has given me a arraylist of the user objects that contains abt 20 users and their details

now wat i did i have kept that in session scope

session.setAttribute("users",user);

now in my jsp i have to display five users in each page
so i wrote the following code to display that

<display:table name="sessionScope.user" pagesize="5">
<display:column property="id" title="ID" />
<display:column property="name" />
<display:column property="email" />
<display:column property="status" />
</display:table>

the properties id,name,email, status are the properties of the object stored in your arraylist that is you have class which actually has getter and setters for these properties.

I think this much is enough for you to complete the functionality

Best Regards
Pankaj
9818418298
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi nanda

ok lets go step by step

1: if you are using struts that mean all the logic is there in your action classes,

ok lets take an example where i will get the users which are deactivated in a discussion forum,

Wat i did in my action class is retrieved the data from datbases which has given me a arraylist of the user objects that contains abt 20 users and their details

now wat i did i have kept that in session scope

session.setAttribute("users",user);

now in my jsp i have to display five users in each page
so i wrote the following code to display that

<display:table name="sessionScope.user" pagesize="5">
<display:column property="id" title="ID" />
<display:column property="name" />
<display:column property="email" />
<display:column property="status" />
</display:table>

the properties id,name,email, status are the properties of the object stored in your arraylist that is you have class which actually has getter and setters for these properties.

I think this much is enough for you to complete the functionality

Best Regards
Pankaj
9818418298
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
Thank you Mr. Pankaj.... I'll try it today and will let you know if i'll face anyproblem... and sir, along with that i'll ask you few questions on struts too. u can answer those if you have time.
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi nanda

I wont have any problem in solving your questions if i know the answers,
and don't call me sir i am just 23 now and think may be equal to your age so it is good that you calll me pankaj


Best Regards
Pankaj
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
hello mr. pankaj... y'day i tried with that display tag. it is working fine. but can u tell me how to change the default layouts... means it has a common format like [First/Prev]....[Next/Last].. i want to replace these with pictures.
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
hi nanda

the layout of this tag library cannot be changed if you want to change them you have to open the taglibrary and search for these words and try replacing them by your images

Best Regards
Pankaj
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
hello Mr. Pankaj. Thank you for your earlier helps. Now I am asking something on another problem. I have a login form which is working fine. I am asking for 3 things on my login form (uid, passwd and utype). now if someone is rewiring the URL like "....?uid=nanda&passwd=nanda&utype=admin" then he can enter the administrator site. I want to restrict this. I mean how can I avaoid this URL hack ? Can you help me please.

Thank u in advance.
Pankaj Narang
Ranch Hand

Joined: Jun 07, 2004
Posts: 81
HI nanda

I think you have not given the method parameter in your jsp, just give method = post near your action tag in your jsp and the everything will vanish from your url

i mean
< form action ="/login" method = post>

Best Regards
Pankaj
Kiran Kumar
Ranch Hand

Joined: May 18, 2001
Posts: 107
HI Nanda,
you can write a Decorator class which extends the TableDecorator/Column Decorator to change the display format as you desire. do go through the documentation for the same.


Thanks<br /> <br />Kiran <br /> <br />SCEA, SCJP 1.4,<br /> <br />"First they ignore u, then they laugh at u, then they fight u, <br />then u will win<br /> <br />Mahatma Gandhi"
N Nanda
Ranch Hand

Joined: Feb 09, 2004
Posts: 62
the default method in struts <html:form> tag is POST. and the Query string is not coming in the URL bar. however, using post method is also expensive. so i was thinking to use GET method rather. anyway, now i am thinking for another solution, Encrypted password. do u hav any idea on this ? how to send an encrypted password to the server and validate it after decrypting the password again.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

ummm... POST expensive? I've never heard that before.

This topic is starting to slip into realms that might be better dealt with by one of the other forums at the ranch, as this is more of a general login authentication question.

Anyway, check out these links:
Different types of authentication

Basic tutorial for using Form-based auth

Hope they help.


A good workman is known by his tools.
 
 
subject: Displaying N rows per page