Forums Register Login

Not rendering EL in my custom tag

+Pie Number of slices to send: Send
Hello fellas,

I'm writing a custom tag and using it in my JSP, but for some reason the EL put in the body isn't being evaluated. Take a look what I did:

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>e-commerce</short-name>
<tag>
<name>bestSellers</name>
<tag-class>tlf.ecommerce.web.tag.BestSellersTag</tag-class>
<body-content>scriptless</body-content>
<description>
List the best sellers.
</description>
<attribute>
<name>top</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

public class BestSellersTag
extends SimpleTagSupport {

private String[] bestSellers = { ... };
private Integer top = 10;

@Override
public void doTag() throws JspException, IOException {
Integer numberOfIteractions = resolveNumberOfIteractions();
for (int i = 0; i < numberOfIteractions; i++) {
getJspContext().setAttribute("bestSeller", i + ". " + bestSellers[i]);
getJspContext().setAttribute("bestSellerUrl", "#something");
getJspBody().invoke(null);
}
}

public void setTop(Integer value) {
...
}
}

<ecomm:bestSellers top="10">
<tr class="navigation_row">
<td class="navigation_sub_cell">
<p><a href="${bestSellerUrl}" class="navigation_link">${bestSeller}</a></p>
</td>
</tr>
</ecomm:bestSellers>


So, I'm not getting any exception, but the ${bestSeller} and ${bestSellerUrl} are being kept as they are, and not being evaluated. Does someone know what's going on?

Thanks
+Pie Number of slices to send: Send
What container and version, and how did you declare the web app in web.xml?
+Pie Number of slices to send: Send
Thanks for replying :-)

Currently I'm using Tomcat 5.5, and bellow follows my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

...

<taglib>
<taglib-uri>/ecomm</taglib-uri>
<taglib-location>/WEB-INF/tld/ecommerce.tld</taglib-location>
</taglib>

I did not put anything to avoid expression language in my web.xml.
[ January 21, 2006: Message edited by: Tiago Fernandez ]
+Pie Number of slices to send: Send
See the JSP FAQ for the correct way to declare your web.xml.

did not put anything to avoid expression language in my web.xml.



Actually, you did. You have declared your app as Servlets 2.3 app, so Tomcat is running in "compatibility mode" and not evaluating the EL properly.

Declaring the app as Servlets 2.4 app will remedy that.
[ January 21, 2006: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Hi Bear,

I didn't realise I had to declare web.xml like that. Anyways, I tried to do it as is said at http://faq.javaranch.com/view?ServletsWebXml

But it didn't work at all :-(

Do you think is anything else to be done?

Thanks a lot.
+Pie Number of slices to send: Send
 

But it didn't work at all :-(



That's not a useful description of the problem.

Did you remove the 2.3 DOCTYPE declaration completely?
+Pie Number of slices to send: Send
Yes, I did remove the DOCTYPE completely. Actually regular EL works fine around my JSP's (it was working before), it just doesn't work with the custom tags I wrote.
+Pie Number of slices to send: Send
Ok, I guess I should have read "Asking Smart Questions" before posting it, hehe... Anyways, I found a lot of effort on https://coderanch.com/t/286030/JSP/java/JSTL-EL-language-not-resolving

Thanks Bear!
[ January 23, 2006: Message edited by: Tiago Fernandez ]
+Pie Number of slices to send: Send
All set now?
+Pie Number of slices to send: Send
Yep, but I still don't believe that enabling EL on Tomcat 5 can be so annoying. Anyways, cheers!
this is supposed to be a surprise, but it smells like a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1492 times.
Similar Threads
Tag body uses an expression
faced error in jsp simple custom tag implemention
Setting bean in Simple tag attribute
body-content as scriptless
Tag with El
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:30:41.