RE: Limiting No of Records per page/view

2002-08-03 Thread Todd G. Nist

Hello Vijay,

You can use the  length and offset attributes of the iterator tag.

The length is used to tell the iterator the number of times/number of items
to retrieve from the collection.

Offset is used to indicate the offset into the collection.

So for example, if you want to display only 10 items of the then you would
do something like this:

logic:iterate id=order
 name=orderlist
 length=10
 offset=0

Hope that helps.

Regards,

Todd G. Nist
-Original Message-
From: Vijay Kumar [mailto:[EMAIL PROTECTED]]
Sent: Saturday, August 03, 2002 4:15 AM
To: [EMAIL PROTECTED]
Subject: Limiting No of Records per page/view



Hi,
I am using Struts  . I need to displays say 10 records per page/view and
give user ability to click on either next button or hyperlink to display
next set of 10 records. User should also have the ability to go back by
clicking previous button. I am able to display all records using iterate
tag, but not able to limit the no of records shown. Any example or code will
be helpful.
This is what i am doing to display records.

logic:iterate id=selling name=table.list

tr
td width=150 height=15 class=tableRowsReadOnly
   nbspbean:write name=selling property=sellingcode/
/td

   td width=150 height=15 class=tableRowsReadOnly
   nbspbean:write name=selling property=season/
/td

/logic:iterate

Cheers
vkvk

_
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com


--
To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]



--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Limiting No of Records per page/view

2002-08-03 Thread Stan Baranek

I use a scroller class that takes an ArrayList of objects. I make the 
objects in the list comparable so the list can be sorted. The scroller 
class uses a simple sorting class to hold the ArrayList. The scroller 
class has public methods like scrollForward(), sortList(), 
getCurrentPage(), gotoPage(), etc. The scroller figures out the proper 
page to display and returns a smaller list of elements. A hyperlink on 
each column heading in the .jsp can trigger a sort event. Subsequent 
clicks on the same column toggle the sort order.

I use the scroller class in my form bean and use methods like 
getDisplayResultsList() to return one page of the list to my .jsp. I 
also limit the number of results returned from the database and use 
light objects in the list so it's not too much of a pig. I think this 
approach works well for small volume applications - you probably don't 
want to use it for a large ecomerce app:-)

I've reused the code for this many times now and find that it's very 
quick to slap into an application and I never have to reinvent the wheel.

This is not the cleanest code in the world but it works well for me:-)

Here is a long-winded code example.

Here is an example of populating the ActionForm.Scroller object with an 
ArrayList of objects to be displayed.
You'll need to implement Comparable on the class of objects you're 
storing in the Scroller if you want to sort.

outputForm.scroller.setScrollList(resultList);
outputForm.setupScroller(); //--- initialize the scroller page size, etc.

Here are some of the key methods used in my ActionForm bean:
Note that the form bean resultList is a short list of one page of data 
that the scroller populates when you scroll
public Object[] getDisplayResultsList() { //--- added to make Struts happy
if (this.resultList != null 
this.resultList.size()  0) {
}
return this.resultList.toArray(); //--- struts likes it this way
}
public int getCurrentPage() {
return this.scroller.getCurrentPage();
}
public int getTotalPages() {
return this.scroller.getNumPages();
}
public int getPageSize() {
return this.scroller.getPageSize();
}
public int getTopIndex() { //--- used for listing current position in 
list (ie: displaying 11 to 20 of 100 total items. Current page 2 of 10. 
Page size: 10)
return this.scroller.getTopIndex();
}
public int getBotIndex() {
return this.scroller.getBotIndex();
}
public int getSortField() {
return this.sortField;
}
public void setSortField(int pSortField) {
this.sortField = pSortField;
}
public String getSortOrder() {
if (this.scroller.getSortAssending())
return A;
else
return D;
}

public void setupScroller() {
this.scroller.setPageSize(10);
this.scroller.setupPages();
this.setResultList(this.scroller.scrollTop());
}
public void scrollScreen(String pScrollFunction) {
ArrayList returnList = null;
if (pScrollFunction.equals(this.scroller.SCROLL_UP )) returnList = 
this.scroller.scrollUp();
else if (pScrollFunction.equals(this.scroller.SCROLL_DOWN )) returnList 
= this.scroller.scrollDown();
else if (pScrollFunction.equals(this.scroller.SCROLL_TOP )) returnList = 
this.scroller.scrollTop();
else if (pScrollFunction.equals(this.scroller.SCROLL_BOTTOM )) 
returnList = this.scroller.scrollBot();
else if (pScrollFunction.equals(this.scroller.REFRESH_SCREEN)) 
returnList = this.scroller.getCurrentScreen();
else if (pScrollFunction.equals(this.scroller.SORT_LIST )) returnList = 
this.scroller.sortList();
else if (pScrollFunction.equals(this.scroller.SCROLL_PAGE )) returnList 
= this.scroller.scrollToPage();

if (this.scroller.getMessageText() != null 
this.scroller.getMessageText().trim().length()  0) {
errors.add(results, new ActionError(scroller.getMessageText()));
}

if (returnList != null) this.setResultList(returnList);
}




import java.util.*;

public class Scroller {
private XYObjArray scrollList = null;
private int listSize = 0;
private int pageSize = 10;
private int topIndex = 0;
private int botIndex = 0;
private int currPage = 0;
private int numPages = 0;
private String messageText = null;
private boolean sortAssending = true;

//--- constants
public static final String SCROLL_TYPE = ScrollType;
public static final String SCROLL_UP = ScrollUp;
public static final String SCROLL_DOWN = ScrollDown;
public static final String SCROLL_TOP = ScrollTop;
public static final String SCROLL_BOTTOM = ScrollBottom;
public static final String SCROLL_PAGE = ScrollToPage;
public static final String REFRESH_SCREEN = RefreshScreen;
public static final String SORT_LIST = SortList;

public Scroller() { }

public void setScrollList(ArrayList pScrollList) throws Exception {
if (pScrollList.isEmpty()) {
Exception ex = new Exception(ERROR: Empty Scroll List when constructing 
Scroller class.);
throw ex;
} else {
this.scrollList = new XYObjArray(pScrollList.toArray(),64);
this.setListSize(this.scrollList.GetSize());
System.out.println(List size in scroller being set to: 
+this.getListSize());
}
}

public void setListSize(int pListSize) {
this.listSize =