views:

52

answers:

1

Hello experts,

We recently switched to Servlet 2.4 and JSP 2 on a project and our custom tags no longer work. We have tags like:

<myTags:someTag value="${x}" />

and once in the tag we evaluated x bean and went from there. Now the evaluation happens directly in the JSP and we get a String (apparently x.toString()) set for the value attribute.

There are not a lot of tags and I could adapt them in a few days but how can I do that? I could not find anything on the web (or maybe I'm not looking where I should).

How do I pass the x bean to my tag and evaluate it there and not allow it to be evaluated in the JSP?

P.S. I do not want to deactivate the EL-engine

Thank you!

+2  A: 

If you redeclare web.xml as Servlet 2.4 as follows

<web-app 
    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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

and the tld file as JSP 2.0 taglib as follows:

<taglib 
    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" 
    version="2.0"> 

Then you can add <rtexprvalue>true</rtexprvalue> entries to tag attributes in the TLD file which are expecting EL values. E.g.

<attribute>
    <name>value</name>
    <rtexprvalue>true</rtexprvalue>
</attribute>

It namely defaults to false.

BalusC
Thanks for your reply. I already have those set up like you say and the thing gets evaluated to String before reaching my tag.
user0912
Did you also update the `tld` file? I updated my answer.
BalusC
Yes. I have Servlet 2.4 in web.xml, web-jsptaglibrary_2_0.xsd for the TLD file. I get a String in the value even if the x bean is something else. What can this be? As you probably guessed from my other question I am not very good at this but basically it should work. What else could I be doing wrong?
user0912
My JSP taglib theoretical knowledge is a bit rusty. I haven't applied this extensively in practice. As next step, try adding a `<type>java.lang.Object</type>` to the `<attribute>`.
BalusC
I managed to make the thing work. Your last comment hit me right in the head and I realized what I was doing wrong. Even if I had all the configurations correctly made I forgot that my tag handler attributes were set to String. I was always expecting a String as the EL expression which I evaluated once in the handler. I was so focused in finding a way to make the same old String arrive to my class to evaluate it, that it did not occur to me to change the attribute type and just receive the object already evaluated from the JSP2. Thank you and sorry for my (can't call it otherwise) stupidity.
user0912
No problem, you're welcome! :) Good that you put the actual solution here.
BalusC