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?
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.
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?
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)
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 by:autobot
This is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking