Levi,
Thanks for your thoughts. However, I believe I am doing things correctly as
follows: this page displays a formatted version of a logfile on the server.
This logfile can be up to 50 MB in size, and a filtering mechanism is provided
so the user can browse the whole file, or certain categories of log entries.
Obviously, with a file of this size, it is not feasible to load it all into
memory at one time, and use a pager tag to display it. Instead, I do the
necessary filtering, and create a list of file pointers to the log entries the
use wishes to see (things are further complicated as the variably length log
entries have to be "reversed" to display in chronologically descending order,
instead of ascending). When the user requests the next page, the next chunk of
log entries are retrieved from the file through the action and displayed.
Everything is working nicely, and I want to put the finishing touches on it to
simply display links to each page, rather than just "next" and "previous". In
my initial action I calculate how many pages I have etc. and simply want to do a
"for" loop to create the links. As Niall pointed out, I could load these page
numbers into a Collection and then use the iterate tag, but this seems to be be
overkill.
Is there really not a Struts tag to do a "for" loop?!!! If not, I belive that
it is a major lack. Are there any plans to introduce one, maybe when the logic
tags are improved?
Thanks. Any other ideas gratefully received!
Dave
"Levi Cook" <[EMAIL PROTECTED]> on 04/27/2001 05:38:22 PM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc: (bcc: David Hay/Lex/Lexmark)
Subject: Re: Iterate certain number of times?
Of course I have no idea what your system actually looks like, but I would
question its retrieving data all the way up to the "view" layer and then not
displaying it.
If possible I would reconsider the design of the "controllers" responsible
for constructing the Collection you are interested in iterating over.
Consider the following method signatures in a hypothetical "controller" for
searching a product catalog:
public Collection findProducts(ProductInfo searchCriteria)
vs.
public Collection findProducts(int startIndex, int count, ProductInfo
searchCriteria)
vs.
public Iterator findProducts(int startIndex, int count, ProductInfo
searchCriteria)
I would expect the first to return a collection of every product in my
entire system. I believ this is probably what your system is doing and I
wouldn't consider it especially useful in a controller responsible for
supporting a view.
The second approach introduces a bit more flexibility by allowing the view
the decide how many products its interested in displaying.
The third approach is probably what I would prefer, I think it just
clarifies the intent of the method for view builders.. Might be a little
stronger form of encapsulation too.
Just my thoughts anyway, hope its useful,
Levi Cook
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 27, 2001 3:46 PM
Subject: RE: Iterate certain number of times?
>
>
> Thanks, but I don't need all that functionality. I have already set up
the
> paging in my actions, but want to generate the links myself simply looping
> through.
>
> Is there not a way to loop through some HTML a set number of times in
struts
> (rather than over a collection)?!
>
> Dave
>
>
>
>
> "Karl Basel" <[EMAIL PROTECTED]> on
04/27/2001
> 04:21:17 PM
>
> Please respond to [EMAIL PROTECTED]
>
> To: [EMAIL PROTECTED]
> cc: (bcc: David Hay/Lex/Lexmark)
> Subject: RE: Iterate certain number of times?
>
>
>
> Hi,
>
> There's a good pager taglib at jsptags.com. I've used it in a struts app
and
> does the job quite well when embedded in the iterate tags.
>
> <logic:iterate>
> <pg:item>
> Item Details
> </pg:item>
> </logic:iterate>
>
> Hope it helps,
> karl
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: 27 April 2001 09:29
> To: [EMAIL PROTECTED]
> Subject: Iterate certain number of times?
>
>
>
>
> Hi.
>
> Am wanting to iterate a certain number of times, based on a value in my
form
> bean, to create a set of page links for the number of pages the user can
> view
> (similar to at the bottom of most search engine results).
>
> How do I do this with Struts? Obviously I am not iterating over a
> collection.
> But surely it is possible - what am I missing?
>
> Many thanks,
>
> Dave
>
>
>
>
>
>
>
>