From the time I started working with JavaEE, I've made my way paginating a list in the .jsp, but I have seen many of Java developers are using display tag library, why, I don't know, as I know display tag library gets the whole list in the page, and only then will process it, and if you still have thousands of entries in the database? what about that? and finally what are the cons and pros of this library?
1 Answers
The tag works with the list of result you give it. It can be results for a page or the entire list which it splits in multiple pages. It is not called a display tag by chance, it actually displays the data you provide it with.
If you have thousands of entries in the database its your job to manage them, not the tag's. The display tag is just a tool. You can use it or look for another tool.
And finally what are the cons and pros of this library?
The display tag (any server tag actually) is used to limit the amount of boiler plate code you have to write for yourself in order to get the job done.
Write the code your way, then write the code using the display tag. Which one is shorter? The display tag’s will be.
If you write a paginating table once in a full moon you don’t really see the benefit, but if you write lots of tables then at some point the time will start to add up. The library use means less boilerplate code to write and it doesn’t add up as much (i.e. it’s faster to write).
One other important thing the tag introduces is consistency. If all the developers use the display tag then all will have an easy time working on each other’s code. Trust me, I have worked with both the display tag and with no display tag. It was a jungle without it. Every developer had its style of creating the pagination, managing interactions at the server, scriptlets all around... it was crazy!
I’m not saying it’s the Holly Grail of paginating tables (for example I don’t use it in one of my pet projects although I have lots of tables to display. But I do have my own custom tag especially designed for my specific purposes which brings me the speed and consistency).
You are not obliged to use the display tag but it is a pretty good library, lots of configurations too. So try reading it’s documentation before making a decision.
-
You say that if all the developers use the display tag then all will have an easy time working on each other’s code. Ok, but how about my implementation that I worked on? I just have to copy/paste it every time I need a pagination, and that's all. For big sites I think rendering a list o thousands rows would be a big problem for display tag library. Well, and if I delete a row from database, the display tag will still renders it, because the list are already in the memory. And I was wondering what others think. Thanks. – Denees Jul 07 '11 at 20:30
-
@hoss: **I just have to copy/paste it every time I need a pagination** Copy/Paste is rarely a good thing in our line of work. **Rendering a list o thousands rows would be a big problem for display tag ... if I delete a row from database, the display tag will still renders it, because the list are already in the memory** Just out of curiosity, are you using SQL calls directly from the JSP to get your data? What does your technique for pagination involve exactly and how is it different of what display tag does? If you provide more details maybe I'll be able to explain better the cons/pros. – Jul 08 '11 at 20:11
-
**Copy/Paste is rarely a good thing in our line of work**, in your opinion the code that I've written in the past can not be used again? and should I invent the wheel every time? **are you using SQL calls directly from the JSP to get your data?**, haha, no man, I'm not using my JSP's to write Java code in them. I have added the Struts tags as well, but M. BalusC has deleted them. Well, doesn't matter at all, not a big thing. – Denees Jul 09 '11 at 05:26
-
@hoss: The code you have written in the past can be used over and over again. But not by copy/paste. Include it in a library or a tag and make a call to get the functionality, don't copy/paste the functionality. Anyways, you haven't answered my question! What are you doing that display tag can't? Is your solution something specific that display tag is lacking or are you creating the same functionality with your own code? If it is nothing specific and you are duplicating what displaytag does then you are in fact reinventing a wheel that was already invented. P.S. I'm interested in your response – Jul 10 '11 at 15:46
-
I am getting from MySQL a limit of n entries with every request, then I send it to JSP. – Denees Jul 11 '11 at 06:38
-
@hoss: I understand. But by using Displaytag, nothing will really change in your flow. You get from MySQL the list with n entries on every request, and then you send this list to the JSP. Inside the JSP you will have the Displaytag which receives the list and displays it. That’s it! Even if you have thousands of entries in the database as you mentioned, the tag won’t touch the database. It wasn’t built for that. Displaytag only displays the data you send it, it does not retrieve the data by itself. – Jul 11 '11 at 19:40