Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Not rendering EL in my custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Not rendering EL in my custom tag" Watch "Not rendering EL in my custom tag" New topic
Author

Not rendering EL in my custom tag

Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
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


Tiago Fernandez
http://www.tiago182.spyw.com/
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

What container and version, and how did you declare the web app in web.xml?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

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 ]
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

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?
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
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.
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
Ok, I guess I should have read "Asking Smart Questions" before posting it, hehe... Anyways, I found a lot of effort on http://www.coderanch.com/t/286030/JSP/java/JSTL-EL-language-not-resolving

Thanks Bear!
[ January 23, 2006: Message edited by: Tiago Fernandez ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

All set now?
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
Yep, but I still don't believe that enabling EL on Tomcat 5 can be so annoying. Anyways, cheers!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Not rendering EL in my custom tag