• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL Functions Vs Custom tags

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Am preparing for the WCD exam and am close to completion. I've neither developed EL functions and custom tags nor used them in any of our JSPs, myself.

But after reading the HFSJ book, it seems both of them serve the same purpose.

Can somebody point me the difference as to when one should go for EL functions and when one should use custom tags - as fas as i see, both of them can be used interchangeably to achieve the same purpose.
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Custom tags are useful when either you need to introduce scripting variables and scoped attributes into the page (okay, you could do this with other actions, but how do you think they work anyway?!) or when you want to process body content (e.g. conditionals like the JSTL <c:if> and <c:choose>).

EL functions are supposed to be quite light-weight with no side-effects. On the contrary, tags almost always do have side-effects such as modifying or created scoped attributes, outputting body content (or not), or even updating databases (see the JSTL SQL actions).

There are a few cases where this is overlap, such as when you use a custom tag like the JSTL <fmt:formatDate /> to convert a Date into a String. In this case you could use either EL or the tag... but EL functions should ideally deal with small amounts of data: counting elements in a list, doing some simple sums, generating a single string. It would be quite inappropriate to generate an entire XML DOM tree in an EL function for example, but quite acceptable in a tag.

Bear in mind also that data emitted from an EL function may be supplied as an attribute value, while tag data rarely is (although this is possible through <jsp:attribute>); you typically don't want lots of data sent to an attribute.

These are only guidelines, but some really firm reasons are that EL cannot generate scripting variables or handle page content terribly well. These are jobs much better left to tags.
[ July 27, 2006: Message edited by: Charles Lyons ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic