GeeCON Prague 2014*
The moose likes JSP and the fly likes Compare between  EL and  TagLib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Compare between  EL and  TagLib" Watch "Compare between  EL and  TagLib" New topic
Author

Compare between EL and TagLib

somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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....


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Hans Bergsten
Author
Ranch Hand

Joined: Dec 01, 2003
Posts: 106
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.


Hans Bergsten, hans@gefionsoftware.com<br />Author of O'Reilly's<br />- JavaServer Pages,<br />- JavaServer Faces<br /><a href="http://www.hansbergsten.com/" target="_blank" rel="nofollow">http://www.hansbergsten.com/</a>
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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

Joined: Dec 01, 2003
Posts: 106
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

Joined: Nov 07, 2003
Posts: 4982
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

Joined: Dec 01, 2003
Posts: 106
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

Joined: Nov 07, 2003
Posts: 4982
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compare between EL and TagLib