• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compare between EL and TagLib

 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I confusing when to use between EL and TagLib , please explain to me
- Advancetage to use EL or TagLib
- Goal of EL and TagLib
thank you very much for all reply.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by somkiat puisungnoen:
- Advancetage to use EL or TagLib
- Goal of EL and TagLib

It makes Non-JSP programmers to easily learn EL and let them want to taste the flavour of the J2EE... It seems like EL is a kind of attacking strategy from JCP to beat the competitors in small- and mid-sized webapps... U might notice that, in Thailand, the market share of J2EE in small- and mid-sized areas is relatively small and it's very difficult to find even a JSP hosting... Because the market share for ASP and PHP is very large in Thailand, I mean... So I hope the evolution of EL will make other developers interested to try JSP... Hope it is what you mean by the goal of EL....
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Ko Ko said, taglib is mainly for Java developers while EL can be done by less experienced Java programmer.
The case I feel is a bit similar to JavaScript. You can access the objects inside the HTML document via JS, such as document.form.action = 'xxx'. You feel JS is easier to read and write. On the other hand, EL is accessing the implicit objects, as well as all Java objects. Also, EL is server side stuffs, while JS is client side stuffs.
Nick.
 
Hans Bergsten
Author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by somkiat puisungnoen:
I confusing when to use between EL and TagLib , please explain to me
- Advancetage to use EL or TagLib
- Goal of EL and TagLib
thank you very much for all reply.

The EL is primarily a language for accessing data in a page, e.g., to get the name of the current user: ${currentUser.name}. It also support the basic operators so that you can do simple math, compare values.
Custom tag libraries (containing tag handlers implementing the behavior for "custom actions") allow you to do a lot of things that the EL doesn't support, such as loop over a data structure to generate a table, add cookies to a response, redirect to another page, parse an XML document, etc.
The introduction of EL functions in JSP 2.0 blurs the line a bit, and it may sometimes be hard to decide whether to implement something as an EL function or as a custom action. There are no hard rules, but it typically easier to implement and use an EL function, so for things that don't involve conditional processing of an element body and only need simple input that can easily be accessed through EL variables, an EL function should be your first choice if you're using JSP 2.0.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hans,

Custom tag libraries (containing tag handlers implementing the behavior for "custom actions") allow you to do a lot of things that the EL doesn't support, such as loop over a data structure to generate a table

If I have a Collection of the object A, can EL, together with JSTL <c:foreach>, can perform the looping?
I remember I have seen this kind of things before, but I forget where did I see.
Nick.
 
Hans Bergsten
Author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:
Hi Hans,

If I have a Collection of the object A, can EL, together with JSTL <c:foreach>, can perform the looping?
I remember I have seen this kind of things before, but I forget where did I see.
Nick.

Sure, I describe this in my book. The <c:forEach> action supports data structures of type Collection, Iterator, Enumeration, Map and arrays of objects or primitive types. One example:
<c:forEach items="${myCollectionOfA}" var="current">
<li>${current.myProperty}</li>
</c:forEach>
assuming the elements of the Collection are beans with a property named "myProperty".
[ March 10, 2004: Message edited by: Hans Bergsten ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hans,
Thus, in fact, maybe using EL alone is less powerful than Custom Tags, however, using EL, say, with JSTL, can provide equal or even more functions that the Custom tags. Am I right?
Are there any examples that a Custom tag can perform, while a combination of EL with JSTL (or other things) cannot?
Nick.
 
Hans Bergsten
Author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nicholas Cheung:
Hi Hans,
Thus, in fact, maybe using EL alone is less powerful than Custom Tags, however, using EL, say, with JSTL, can provide equal or even more functions that the Custom tags. Am I right?
Are there any examples that a Custom tag can perform, while a combination of EL with JSTL (or other things) cannot?
Nick.

Well, JSTL is a collection of "custom tags", except that they are defined by a public specification; they can be implemented using exactly the same API as any other custom tag. In JSP 2.0, you can use EL expressions to provide input to any type of custom tag, whether it's part of JSTL or a library you developed yourself.
It's not really and either or thing; the EL and "custom tags" (formally, "action elements") are intended to be used together. Like I mentioned earlier, the EL is primarily a language for accessing data (e.g., to provide input to the action element attributes), do simple math and compare values. You can't use the EL to set response headers, loop over the elements in a collection, execute a database query, parse an XML document, etc.
Action elements can be implemented as Java classes, so they can do anything any regular Java class can do. They also interact with the JSP container to tell it what to do with the action element's body, e.g., include it as-is in the response or evaluate other action elements in its body zero or many times.
I think the best way to understand the difference is to look at some examples that use both. You can download all examples from my book at:
http://www.thejspbook.com/
You need a JSP 2.0 container (such as Tomcat 5) to run the examples from the 3rd edition, but the examples from the 2nd edition works with a JSP 1.2 container.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hans,
Thanks a lot. Since I use WSAD 5.1, and it is able to understand JSP 2.0, I think I have no problem in running the sample codes.
Thanks a lot.
Nick.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic