Accepting EL Expressions in Custom JSP Tags

T

Tom Cole

Is there anything special that needs to be done to accept EL
Expressions as attribute values in a custom tag? I have a tag library
that I'd like to use with JSTL to generate database driven apps, but
apparently there must be something I need to do to get my tag to
understand it...

The goal is to be able to use my tags inside sql and c tags. FWIW all
my tags extend TagSupport or BodyTagSupport.

Thanks
 
T

Tom Cole

Apparently none. I just rewrote a simple test using request parameters
instead and it worked.

An example of what I was trying to do is:

<sql:query var="addresses" dataSource="jdbc/mySQL" maxRows="10">
SELECT addr, city, state, zip FROM myTable
</sql:query>
<c:forEach var="address" items="${addresses.rows}">
<mytags:geocode address="${address.addr}" city="${address.city}"
state="${address.state}" zip="${address.zip}"/>
</c:forEach>

However I was not getting output, the page was just spinning and
spinning. The query takes a whole millisecond normally and there were
no errors posted to the logfile.

I'm just learning JSTL (I've preferred not to use any type of logic
like this in the client side, however potential users of my taglibrary
would) so it might be my JSTL code here.

The taglibrary is for generating GoogleMaps, so I can see customers
wanting to integrate JSTL to pull addresses from database tables...

The JSTL code will go inside one of my tags (that extends
BodyTagSupport and returns EVAL_BODY_INCLUDE from the doStartTag() and
will then in turn have other tags inside it.

You can go to http://www.lamatek.com/GoogleMaps/ and you'll probably
see exactly what I'm talking about.

Thanks for your assistance.
 
R

Raymond DeCampo

Tom said:
Apparently none. I just rewrote a simple test using request parameters
instead and it worked.

Yes, I believe the EL expressions are evaluated by the JSP engine before
passing the parameters to your custom tag.
An example of what I was trying to do is:

<sql:query var="addresses" dataSource="jdbc/mySQL" maxRows="10">
SELECT addr, city, state, zip FROM myTable
</sql:query>
<c:forEach var="address" items="${addresses.rows}">
<mytags:geocode address="${address.addr}" city="${address.city}"
state="${address.state}" zip="${address.zip}"/>
</c:forEach>

However I was not getting output, the page was just spinning and
spinning. The query takes a whole millisecond normally and there were
no errors posted to the logfile.

I'm just learning JSTL (I've preferred not to use any type of logic
like this in the client side, however potential users of my taglibrary
would) so it might be my JSTL code here.

Perhaps this was simply a typo on your part, but JSTL executes on the
server side. So the logic would not be on the client side.
The taglibrary is for generating GoogleMaps, so I can see customers
wanting to integrate JSTL to pull addresses from database tables...

The JSTL code will go inside one of my tags (that extends
BodyTagSupport and returns EVAL_BODY_INCLUDE from the doStartTag() and
will then in turn have other tags inside it.

You can go to http://www.lamatek.com/GoogleMaps/ and you'll probably
see exactly what I'm talking about.

Thanks for your assistance.

It sounds like everything is working, except for the example with the
<sql:query> tag correct? In that case, since your tag works with the
request parameters, you may want to simply remove your tag and
concentrate on debugging the <sql:query> portion.

HTH,
Ray
 
J

josh.s17

Try using c:eek:ut with the EL. eg

address=<c:eek:ut value="${addresses.addr}"/>

in the place of the EL by itself.

address="${address.addr}"

When using JSTL with the earlier versions of JSP you will need to do
this
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top