Passing value of an EL expression into a custom tag (tag file)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Eric_Rizzo
Posted On:   Thursday, April 27, 2006 01:00 AM

I'm trying to use tag files to write simple custom tags (as opposed to TLDs and Java classes). My problems arise when I want to pass, from the calling page, the value of an EL expression as the value of an attribute to the custom tag. For example, say I have a .tag file myCustomTag.tag that declares an attribute called recordNumber, like this: <%@ tag language="java" body-content="empty" %> <%@ attribute name="recordNumber" required="true" %> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> Record number is And then in the calling page I have a variable in scope called aRecord, which   More>>

I'm trying to use tag files to write simple custom tags (as opposed to TLDs and Java classes). My problems arise when I want to pass, from the calling page, the value of an EL expression as the value of an attribute to the custom tag.


For example, say I have a .tag file myCustomTag.tag that declares an attribute called recordNumber, like this:

			
<%@ tag language="java" body-content="empty" %>
<%@ attribute name="recordNumber" required="true" %>

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

Record number is


And then in the calling page I have a variable in scope called aRecord, which has a property named "number." I try to call my custom tag as follows:

			
...

...


I'm looking to the output to be something like this (where 123 is the value of number for aRecord):

			
Record number is 123


However, the output I'm getting is:
			
Record number is ${aRecord.number}


It is as if the calling page invocation of myCustomTag is not evaluating the initial EL expression before invoking the custom tag.

I've looked for tutorials and examples of custom tag files all over the web, but none seem to do this kind of thing (which I would expect to be very common need).


What am I missing?

   <<Less

Re: Passing value of an EL expression into a custom tag (tag file)

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, May 3, 2006 06:52 PM

I think you have to pass your incoming values through an EL expression evaluator?



I've seen taglib code where this is done. I don't know if it's supposed to be necessary when running on JSP 2.0-compliant servlet containers? but it's definitely necessary on older servlet containers, from what I can tell (I haven't tried to tinker with this code yet).
About | Sitemap | Contact