• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Are custome tags useful?

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Custom tags are as useful as any other user-defined data type.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out this thread for more information
https://coderanch.com/t/165729/java-Web-Component-SCWCD/certification/Benefits-custom-tags
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
     
    Sheriff
    Posts: 7001
    6
    Eclipse IDE Python C++ Debian Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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: 7001
    6
    Eclipse IDE Python C++ Debian Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Posts: 1913
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic