This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes EL versus Tag Libraries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "EL versus Tag Libraries" Watch "EL versus Tag Libraries" New topic
Author

EL versus Tag Libraries

Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Ok, a regular mock question is that to pick the based way to remove code duplication from a web application written in JSPs.
This could be done using the Expression Language or Tag Libraries? Which is better and why?

Discuss...
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11490
    
  95

A better way to raise this question here would be to make note of some points in favor of either technology and then ask others what they think.

One of the things about being an architect is that you will be asked which technology should be used, and you will need to research different options and make decisions.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

Luke,

Cmon, ask a specific question and then people can respond ....

don't just say 'discuss' ...


kf
SCJP 5.0 (preparing for SCWCD)
Luke Murphy
Ranch Hand

Joined: May 12, 2010
Posts: 300
Ok, here's how see it. I can see how writing custom tag libraries had their place in the early days of JSP but now the JSP has matured I don't see how writing a custom tag libary has any advantage over using EL. With the advent of JSTL there was no need for developers to write a lot of custom tags they had been writing as JSTL provided an industry standard way of doing this. JSTL and EL sit nicely together and can be used together. It is much easier to write a bean to do something or encapsulate something and then reference it from an EL then it is to go off writing custom tags.

so I'll put the question this way can you do anything with a custom tag that you can't do with EL?

Keith Flo
Ranch Hand

Joined: Nov 29, 2005
Posts: 128

Luke,

Here's my view ...

  • as a developer I can do just about anything I might need or want to do when I can use Java ... taglibs let me do this
  • when I write a custom tag other developers (even non-developers) can use the functionality of the tag very easily. Just put the taglib directive in at the top of the JSP page and 'boom' they can use the functionality the tag provides.
  • Custom tags can have input arguments and allow you to return html ... returning html is more convenient that the text that your bean is (most likely) to provide.
  • Lastly, EL and JSTL are nice ... but they dont provide everything ... for example Struts2 has it own taglib for things you may need that aren't provided by JSTL (like html forms)
  • Christophe VerrĂ©
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    so I'll put the question this way can you do anything with a custom tag that you can't do with EL?

    Re-usability. EL does not remove code duplication. Imagine that you make some kind of html tables using a JSTL c:forEach loop and EL, how would you make it reusable ? By making a custom tag, which would hold the main logic, use EL if necessary, use other custom tags if necessary... Well known MVC framework usually have their own set of custom tags.

    It is much easier to write a bean to do something or encapsulate something and then reference it from an EL then it is to go off writing custom tags.

    For the View layer, no. You'll need some logic to display the data hold by a bean, and this is not the bean's responsibility to do it. This is usually done via custom tags (including JSTL), or pure EL if this is enough.


    [My Blog]
    All roads lead to JavaRanch
     
    wood burning stoves
     
    subject: EL versus Tag Libraries