aspose file tools*
The moose likes JSP and the fly likes custom taglib problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "custom taglib problem" Watch "custom taglib problem" New topic
Author

custom taglib problem

Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Apr 26, 2004
Posts: 207
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Apr 26, 2004
Posts: 207
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: custom taglib problem