• 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

Not rendering EL in my custom tag

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What container and version, and how did you declare the web app in web.xml?
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All set now?
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, but I still don't believe that enabling EL on Tomcat 5 can be so annoying. Anyways, cheers!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic