• 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

EL works in attr value to html, but not in custom tag attr value

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi -

I find the issue of when EL works and doesn't to be quite a challenge. I wrote a custom tag handler but I can't pass an EL expression as an attribute value into the tag.

This works (simple html with EL in attribute value):

<%@ taglib uri="/WEB-INF/c-1_0.tld" prefix="c" %>
<a href="<c:url value="${module.initialFlow.initialAction.path}"/>">
Label
</a>


This works (my custom tag with no EL):

<%@ taglib uri="/WEB-INF/c-1_0.tld" prefix="c" %>
<nav:notifyUnsavedChangesLink2 href="link.do">
Label
</nav:notifyUnsavedChangesLink2>

This doesn't work (my custom tag with EL in attribute value):

<%@ taglib uri="/WEB-INF/c-1_0.tld" prefix="c" %>
<nav:notifyUnsavedChangesLink2
href="<c:url value="${module.initialFlow.initialAction.path}"/>">
Label
</nav:notifyUnsavedChangesLink2>

Neither does using this (the c-1_0-rt.tld):
<%@ taglib uri="/WEB-INF/c-1_0-rt.tld" prefix="c" %>

What fundamental piece of knowledge am I missing?

thank you,
Steve
 
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you remember to include the attribute element in the TLD for the tag? I believe you also need to set rtexprvalut to true.
 
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 version of JSP are you running? I got the impression that it's JSP 2.0. If that is the case, you should be using the JSTL 1.1 -- looks like you are using 1.0.

Also, you should be using the standard URI's for the JSTL rather than making up your own. That would make it easier to tell what's going on.
 
Steve Line
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What version of JSP are you running? I got the impression that it's JSP 2.0. If that is the case, you should be using the JSTL 1.1 -- looks like you are using 1.0.



Right now we're limited to using JSP 1.0 because we're deploying to WebSphere 5.0.

You're right I started writing a tag file implementation (JSP 2.0), but had to back up due to our customer's version of WebSphere.

Also, you should be using the standard URI's for the JSTL rather than making up your own. That would make it easier to tell what's going on



Why? I don't understand the difference. Is the standard URI just a name, or does the app actually go to that location and download something? I also don't understand the difference between c_1.0-rt.tld and c_1.0.tld.

Should my example work with JSP 1.0?

Did you remember to include the attribute element in the TLD for the tag? I believe you also need to set rtexprvalut to true.



Yes the attribute name, href, is an attribute in the .tld file, and the rtexprvalue is set to true. Below is the .tld entry:



Steve
 
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

Why? I don't understand the difference. Is the standard URI just a name, or does the app actually go to that location and download something?



The URI is used to match up the tag declaration with the appropriate TLD file (which declares the URI within itself). The container will automatically search for such TLD files in the WEB-INF folder hierarchy and in the META-INF folder of jar files in the classpath.

URIs are just identifiers, and, despite their appearance, are not URLs. No remote access is performed.

It's best to use the standard URIs for two reasons:

1) The above auto-discovery mechanisms can be used so that there's no need for declarations in the web.xml deployment descriptor. And simple is better.

2) Everyone familiar with the TLDs in question will recognize the standard URIs and know what your intentions are.

I also don't understand the difference between c_1.0-rt.tld and c_1.0.tld.



In JSTL 1.0, the difference between the rt and the non-rt libraries is that the rt libraries accept run-time expressions as attributes. Under JSTL 1.1 (which relies upon the JSP 2.0 engine to handle the EL) there is no need for such a distinction.
[ July 19, 2005: Message edited by: Bear Bibeault ]
 
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 had to back up due to our customer's version of WebSphere.



Bummer!
 
Steve Line
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I put this:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

at the top instead of '/WEB-INF/c_1.0.tld', but it still doesn't work. I get:

Unterminated <nav:notifyUnsavedChangesLink2 tag

Any ideas?

Thank You,
Steve
 
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
Oh, sorry! I thought I had posted an earlier response to this effect, but it's not there! Must've been a pre-caffeine fumble where I wrote the reply but never hit the add button.

You can't do what you are trying to do:



You are trying to use an action (JSP-speak for "custom tag") as the attribute to another action. No can do. Not in JSP 1 or in JSP 2.

Additionally, under JSP 1, you can't even use the EL anywhere but in the JSTL tags. With JSP 2, the container evaluates the EL, but under JSP 1, it's JSTL-only.

While you're stuck in the JSP 1 world, you're going to have to resort to scriptlets and scriplet expressions when dealing with non-JSTL custom actions.

As I said, bummer!
 
Steve Line
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! Now I'll stop beating my head against that wall and find another.

Steve
 
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
Under JSP 2 you could do the foillowing:



under JSP 1 (I have no means to test this so it may need tweaking):

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
alternatively you can follow the struts pattern, and provide a "name" attribute which tells the tag what name to look up in the attributes in order to find the value.

ie
<c:url value="${module.initialFlow.initialAction.path}" var="myUrl"/>
<nav:notifyUnsavedChangesLink2 hrefName="myURL">

and then in your tag

String href = "";
if (hrefName != null && !hrefName.equals("")){
href = (String)pageContext.findAttribute(hrefName);
}

Cheers,
evnafets
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic