Why custom tags?


Web tier: servlets, JSP, Web frameworks: Why custom tags?

  1. Why custom tags? (4 messages)

    Why are custom tags taken for granted as the "right" way to add functionality to JSPs? Why not just create libraries of static Java routines, then call those as JSP expressions?
    Here's an example of the Struts iterate tag:

    <logic:iterate id="element" name="myhashtable", scope="session">
    <br><bean:write name="element"/>

    Why not just code a static String method that does the same thing:

    <%= HtmlUtils.iterate(session.getAttribute("myhashtable"), "<br>?")%>

    Of course, you are free to make up your own parameter list -- you could have the using code pass "page", request, or response if those would be handy.

    The training cost for the HTML programmer would be the same: It takes the same effort to learn a new JSP tag such as logic:iterate, as it is to learn how to call a new static method. (The static method call is probably a little simpler.)

    The organization benefits because you no longer have to manage TLDs. Documentation of these static methods is easy because you use Javadoc. The organization also benefits because the learning curve for coding some static routine is lower than the learning curve for implementing a custom tag.

    Threaded Messages (4)

  2. Why custom tags?[ Go to top ]


    I think you are right on target here. We use HtmlBuilder classes to remove looping from JSPs. It's much easier to write Java code in a Java IDE than in a JSP editor.

    Also you make an excellent point - "Why should a developer learn a the new syntax for a tag library?"

  3. Why custom tags?[ Go to top ]

    For many things it is more natural. Which is easier to understand and learn?

        if (request.getUserPrincipal() != null) {
        } else {


    <%= HtmlUtils.getUserName() %>



  4. Why custom tags?[ Go to top ]

    I believe the original idea behind using custom tags within JSPs was the belief that HTML developers would be creating/modifying the JSP files. Therefore, you wouldn't need to teach your HTML developers Java, they'd just need to learn your new custom tags. Also, it is easier to incorporate custom tags into IDEs for JSP WYSIWYG.

    What I've seen is that the Java developers are the ones creating/modifying the JSPs and therefore find it easier to just write Java code versus creating custom tags. For most application development groups this is probably OK, but I think the idustry will continue to push custom tags. Hopefully they can simplify the spec and reduce the initial learning curve.

  5. Why custom tags?[ Go to top ]

    Apologies for cross-linking forums, but there's some more discussion on the same question here ... http://www.javaranch.com/ubb/Forum7/HTML/006220.html