Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL versus Tag Libraries

 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11945
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luke,

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

don't just say 'discuss' ...

 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic