• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are custome tags useful?

 
Varun Narula
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have just been reading on custom tags and was unable to find a suitable example where it could be used.
Can you mention use of these tags in some of your live projects ??
Varun Narula
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Custom tags are as useful as any other user-defined data type.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this thread for more information
http://www.coderanch.com/t/165729/java-Web-Component-SCWCD/certification/Benefits-custom-tags
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some examples include:
  • iteration over uniform and hierarchical collections (such as menus for navigation)
  • conditional logic
  • presenting content based upon security roles
  • locating information from the model (in MVC)
  • locating information from an EJB layer (in smaller apps)
  • checking values of cookies
  • generating HTML controls such as drop downs and lists from collections of JavaBeans


  • Basically, tags are great for any type of presentation related logic that you would normally code with scriptlets.
    There are many, many more uses but I hope that's useful for starters...
    Simon
    p.s. check out the sample chapters from Professional JSP Tag Libraries for some more examples
    [ July 18, 2002: Message edited by: Simon Brown ]
     
    Frank Carver
    Sheriff
    Posts: 6920
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    For me the "bottom line" with custom tags is that they are another way of getting code out of scriptlets and into proper Java.
    I have been burned too many times with bugs and even compilation errors in scriptlets which don't show up until long after a web application has been deployed. Now I hate seeing code in JSPs.
    Custom Tags allow all that yucky scriptlet code to be simply moved to regular Java classes, where it can be compiled and tested before deployment rather than waiting for the live system to fail.
    Also, because they are well-formed XML, you can use XSLT to style your JSPs. Bonus!
     
    Varun Narula
    Ranch Hand
    Posts: 90
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Is there something that can only be done by using Custom tags ?
    Is the primary objective of custom tags separation of Java code from the HTML ??
    Varun Narula
     
    Frank Carver
    Sheriff
    Posts: 6920
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Is the primary objective of custom tags separation of Java code from the HTML ??
    Yes, and all the side benefits that gives: compilation and testing of code before deployment, more readable JSP source, easier re-use of tag code etc. etc.
    I can't emphasize this enough, putting raw Java scriptlet code in JSP pages is bad. You should feel naughty when you do it, and move the code out to something more reliable, readable, reusable and testable as soon as you can.
     
    Simon Brown
    sharp shooter, and author
    Ranch Hand
    Posts: 1913
    6
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Varun Narula:
    Is there something that can only be done by using Custom tags ?

    Frank is right, there are so many benefits in using tags over code in the page.
    As for something that can't be achieved (easily) using scriptlets, check out this thread.
    Simon
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic