Matt Hughes said:
> Well, you know what your pageSize is going to be ... so why can't you
> prepare the Vectors with that size?

Two factors:

* You don't necessarily know the page size.  With model-view separation, a
designer can just decide to change the page size.  Since you're jiggering
the Vector before the <display:table> tag, you DON'T know the page size in
that case.  You can have a variable declaration earlier in the page and
use that in the calculation and in a scriptlet in the pagesize attribute
for the <display:table> tag, but that's re-introducing (an admittedly
small) amount of Java code back into the page.

<% int pagesize = 20;

// Create vectors in bean or list or whatever based on pagesize.
%>

<display:table pagesize="<%= pagesize %>">
   ...
</display:table>

* That really complicates the Vector prep.  Without pagination, you'd
calculate the offset (that is, the number of list items to skip when
starting the second column) with the formula:

Vector items = ...;
int offset = items.size() / 2 + items.size() % 2;

Now you calculate the contents of each vector, one with all items from 0
to offset - 1, the other from offset to items.size() - 1.

That's easy enough.  But once you add in pagination, you have to do this:

Vector items = ...;
int pagesize = ...; // Get pagesize from the JSP page, not good form.
Vector items1 = new Vector();
Vector items2 = new Vector();

for (int page = 0; page < items.size() % pagesize + 1; page++)
{
   for (int i = 0; i < pagesize; i++)
   {
      Object o = items.get(i);
      items1.put(o);
      o = items.get(i + pagesize);
      items2.put(o);
   }
}

This will fail, of course, since probably in the lower for loop you'll get
something that doesn't actually exist in items, so you'll need to deal
with that too.

All of that is a lot more complicated than:

<display:table pagesize="10" columns="2">
   ...
</display:table>

Which is what both the OP and I think would be a cool feature.

-- 
Rick Herrick
[EMAIL PROTECTED]

Proud member of the reality-based community

Never try to discourage thinking for you are sure to succeed.--Bertrand
Russell


-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to