my dog learned polymorphism*
The moose likes Servlets and the fly likes TagLibs in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "TagLibs in JSP" Watch "TagLibs in JSP" New topic
Author

TagLibs in JSP

Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi,
I was wondering, when to use the Taglib feature of JSP.We could use the JavaBean feature to do most of the presentation logic.
Is there a performance hit, if we decide to put the presentation logic in the JavaBean instead of using the Taglibs?
The only advantage that I can see using taglibs is that, the JSP becomes concise.However, it becomes more cryptic to a HTML designer who may not be a decent Java programmer.In that case, it goes against the principle on why JSP is prefered over servlets - allowing Web designers to work in parallel with the Java Developers so that static content is separated from dynamic content.
Please advise.
Regards,
Sandeep Desai
[This message has been edited by Desai Sandeep (edited April 24, 2001).]


<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
Dustin Marx
Ranch Hand

Joined: Mar 06, 2001
Posts: 40
If you can do everything you need with JavaBeans rather than custom tags, I would probably lean that way. However, I have run into things that can only be done in Java scriptlets or in custom tags. This includes things like passing collections (rather than scalar values) and handling iterations. If all you need Java in your JSPs for is storing and retrieving scalar values, JavaBeans should do the work nicely. However, if you need to employ significant Java processing with the JSPs, custom tags seem more appropriate to me.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Dustin,
Thanks for the response.
As regards handling iterations, I have done that through the JavaBean code.Is there any reason, why I need to switch that code to the custom tag?
Also, could you please clarify on what you meant by passing Collection?Are you trying to pass HashSets, HashMaps, Vectors, etc.Could you please post a sample code here.
Thanks in advance
Regards,

------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
Dustin Marx
Ranch Hand

Joined: Mar 06, 2001
Posts: 40
Thanks for the reply.
When I was talking about collections, I was talking in general terms about any of the collections you listed or others. Although JavaBeans can handle these, we are trying to avoid the need to have Java Scriptlets in the JSP to iterate over the returned collections. Thus, for us, the only way to reduce the Java in the JSP and handle non-scalar data is to use custom tags that iterate for us. I guess there are other ways of handling these collections with JavaBeans and avoiding Java code in the JSP (such as storing a "list" of elements in a single String with a delimiter marking each element), but we decided it was more straight-forward to use custom tags.
I would say it comes down to trade-offs between the two approaches and what you are most comfortable with. I know many people aren't bothered in the least by mixing HTML and Java in their JSPs while others will go to any length required to completely separate the two.
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Dustin,
Thanks for your reply.
If I consider iterating through the collection and creating the HTML form in the JavaBean code, instead of doing it with custom tags,what I understand is, there would not be any performance hits.
It just boils down to the fact, whether you are comfortable using JavaBeans or the custom tags...Right?
The only other consideration (or should I say cons!!) with JavaBeans is that you cannot avoid scriplets completely, like custom tags..Right?
Thanks in advance,
------------------
Sandeep Desai
vgdesai@bom3.vsnl.net.in

  1. Sun Certified Java Programmer Scored 93 per cent
  2. Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  3. IBM Enterprise Connectivity with J2EE Scored 72 per cent
  4. Enterprise Development on the Oracle Internet Platform Scored 44 out of 56
Dustin Marx
Ranch Hand

Joined: Mar 06, 2001
Posts: 40
I believe you are correct that there are no significant performance differences. As far as I can tell, I agree that the main deciding factor for determining whether to use JavaBeans or custom tags is your tolerance for Java scriptlets in the JSP. Maybe someone else knows of some other differentiating factors?
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92
In my case, I was told to do a customerize tag lib so that in the future, the client side developer can just use the tag, which will be the only code that is sort of java in the page, and it would be easy for them to learn because of the format.
tag lib has certain limitation comparing to bean
just my $0.02
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TagLibs in JSP