• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

custom taglib problem

 
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a simple tag library that I'm trying to pass a list into...so the taglib class can display the contents of the list in a loop.

I'm pretty sure I've got the taglib nailed but the problem I'm having is in the JSP where I'm calling it.

Here's my taglib class:



Here's my tld file:



Here's my JSP:



I get this error when running:



I've never done much nesting of java code directly into JSPs, I usually use RequestDispatcher to forward the request to a JSP in an MVC setup.

So, I'm sure I'm doing something really stupid but I'm not sure what it is.

I also tried this, thinking I had to declare the list first:



...but that's obviously wrong...as seen in the error:



What do I do now?

Thanks!

-v
 
Sheriff
Posts: 67754
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

I've never done much nesting of java code directly into JSPs



Now isn't the best time to start, in my opinion.

But... it looks like the error you are getting may be because your JSP container is not using a Java 1.5 compiler and is choking on the generic notation.

But there's another "but"... even if that was working, you've got a serious misconception. The variable list is a scripting variable, which you then try to reference using the EL. No can do. The EL and Java scriplets on the page live on separate planes of existance (one reason to avoid starting to put Java on your pages).

The EL is used in conjunction with scoped variables; what you probably currently think of as page/request/session/application attributes.
[ October 15, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67754
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
And completely aside:

<%!
java.util.List<String> list = new java.util.ArrayList();
%>



Even more than avoiding Java scriptlets in general, avoid declarations like the plague. They will cause you nothing but heart-ache and pain! (In other words: introduce thread-safety issues that will make your life miserable).
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree, I'm only putting code in there as a test...just to see how custom taglibs work w/ collections...this type of pasta would never happen in a production app (on any platform be it Java, .NET, etc.)

Tomcat 5.5.9 on this box appears to be using 1.5 as I'm using it in servlets...why would it barf in a JSP if a generic list works fine in a servlet in the same container?

So, in an MVC/RequestDispatcher setup if I were to have passed the list as an attribute (request.setAttribute()) then it would have found it as ${list} just fine...according to what you're saying.

...or even if I had just created a jstl variable (i.e. <c:set var="list" value="<% list %>" /> - then it could have passed into the JSTL plane of existence ??

Thanks Bear (as usual!)

-v
 
Bear Bibeault
Sheriff
Posts: 67754
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 would it barf in a JSP if a generic list works fine in a servlet in the same container?



Tomcat doesn't compile the servlet, but it does compile the JSP. I'm not using Java 1.5 and Tomcat 5.5 yet, so I'm not completely savvy on the issue. But the error message is pretty clear in that it's choking on the generic notation.

I agree, I'm only putting code in there as a test



<sigh of relief>


if I were to have passed the list as an attribute (request.setAttribute()) then it would have found it as ${list} just fine

or even if I had just created a jstl variable (i.e. <c:set var="list" value="<% list %>" />



Yes, and yes (I think, except that the syntax would be value="<%= list %>")

But for testing, I'd just use pageContext.setAttribute( "list", list ) in your scriplet.
[ October 15, 2005: Message edited by: Bear Bibeault ]
 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sooo, Bear, how would a guy "force" Tomcat 5.5.x to conform to Java 1.5?

I tested the rest, the initial issue is resolved - everything works.
 
Bear Bibeault
Sheriff
Posts: 67754
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

ow would a guy "force" Tomcat 5.5.x to conform to Java 1.5?



Sorry, not my ken. Circumstances have kept me in the Java 1.4/Tomcat 5.0 world for the time being.

Have you searched the Tomcat forum? This issue has a ring of familiarity to it...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Starting with version 5.5, Tomcat is being shipped with the JDT compiler (from Eclipse) to compile the JSPs.

JDT isn't fully compliant to the Java 5 syntax yet.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic