• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Problems making Struts/JSTL 1.2 site work with JSTL 2.0

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a working web site using JSP, Struts and JSTL 1.2. It is hosted by Tomcat 5.5.

In the web pages I use constructs such as <c ut value="${quoteSearchForm.quoteTopic}"/> and an extended version of <c:forEach> that sets values for items, begin and end using EL (such as items="${quoteSearchForm.quotes}"). The reference to the core is:

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

The web.xml file is of servlet 2.3 format (a <DOCTYPE> starts it) and I am using a version of standard.jar that contains only the c.tld version of the JSTL core libraries.

I want to be able to edit, deploy and debug my web site from inside of Eclipse or NetBeans. The web project(s) created from within those packages use a web.xml file of servlet 2.4 technology. This file starts with <web-app version="2.4" ...>, with a typical schema information in that tag. So, OK, copy over the existing stuff and things will compile and work.

Except no. The web page won't compile. It complains that c ut won't take EL expressions in its "value" attribute. I try fixing that by copying over new versions of standard.jar, and when that doesn't work fix my version of the forEach extender to allow EL expressions, then fix the taglib reference and web.xml reference to work together. I finally get a compile.

When I run the page I get an exception:

javax.servlet.jsp.el.ELException: Unable to find a value for "quoteStatus" in object of class "java.lang.String" using operator ".",

It is complaining about:

<halo:forEachCycle items="${quoteSearchForm.quotes}"
var="quotes" varStatus="loop"
begin="${quoteSearchForm.detailsStartIndex}"
end="${quoteSearchForm.detailsEndIndex}"
cycleId="cy" cycleItems="#D4D0C8 #BBBBBB">
<tr height="20" bgcolor='<c ut value="${cy}"/>' >
<c:choose>
<c:when test="${quotes.quoteStatus eq STATUS_OPEN}">
...

Consider the <c:when> above. Basically, when I use the old standard.jar and its c.tld I get this compiled into the web page:

_jspx_th_c_when_1.setTest("${quotes.quoteStatus eq STATUS_OPEN}");

And when I use the new standard.jar and its c.tld I get this compiled into the web page:
_jspx_th_c_when_1.setTest(
((java.lang.Boolean)
org.apache.jasper.runtime.PageContextImpl.
proprietaryEvaluate("${quotes.quoteStatus eq STATUS_OPEN}",
java.lang.Boolean.class,
(PageContext)_jspx_page_context,
null, false)).booleanValue());

When proprietaryEvaluate() gets called, it thinks that a String, and not my Object, is involved.

=#=#=#=

What I am wishing for here is a configuration explanation to line up all of the bits I need to get JSTL 2.0 working with my program.

Thanks in advance,

Jerome Mrozak
 
Sheriff
Posts: 67750
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
You seem a bit confused about versions and such. There is no JSTL 2.0. And as far as I know, no implementation of JSTL 1.2 yet.

When you say JSTL are you meaning JSP?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a whole FAQ on this, but basically.

Changing from Servlet2.3/JSP1.2 to Servlet2.4/JSP2.0
You have to change from JSTL1.0 to JSTL1.1
Your taglib import statement has to change to be:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Sounds like you have done everything you need to get the container working correctly.

I presume that that halo:forEachCycle tag is custom made? It extends the standard forEach tag? It quite possibly needs to be tweaked to work with JSP2.0 container. Which class exactly does it extend?

There are two implementations of the forEach tag in the JSTL. One that takes EL expressions, and one that takes runtime expressions.
org.apache.taglibs.standard.tag.el.core.ForEachTag
org.apache.taglibs.standard.tag.rt.core.ForEachTag
The fix may be as simple as changing which class your custom forEach tag extends.

So you will have two different versions of this tag. One for JSP1.2 containers, and another for JSP2.0 containers (much like the JSTL is)

Explanation:
One of the main additions in JSP2.0 was the EL.
It is not supported under JSP1.2, so JSTL 1.0 had its own parser/evaluator for EL expressions. That is why you could only use EL in the JSTL tags.
Under JSP2.0, these EL expressions are now treated as runtime expressions, and are evaluated by the container.

Hope this helps,
evnafets
 
Jerome Mrozak
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my standard.jar there is a c.tld, which has these initial lines:

<?xml version="1.0" encoding="UTF-8" ?>
<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">

<description>JSTL 1.1 core library</description>
<display-name>JSTL core</display-name>
<tlib-version>1.1</tlib-version>
<short-name>c</short-name>
<uri>http://java.sun.com/jsp/jstl/core</uri>;

That is where I get the "2.0" from.

My web.xml begins with:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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">
<display-name>Struts-enabled WebStar</display-name>

and it doesn't contain any definition for "core" or "c.tld".
There is no "c*.tld" in my WEB-INF directory.

***

The web.xml contains a definition for my extension of the forEach tag. In web.xml is this definition:

<taglib>
<taglib-uri>/tags/halo</taglib-uri>
<taglib-location>/WEB-INF/halo.tld</taglib-location>
</taglib>

Which was:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.0</jsp-version>
<short-name>halo</short-name>
<uri>http://halo.com</uri>;
<display-name>Halo library</display-name>
<description>Halo library</description>

<tag>
<name>forEachCycle</name>
<tag-class>com.halo.portal.struts.ForEachCycleTag</tag-class>
<tei-class>com.halo.portal.struts.ForEachCycleTei</tei-class>

combined with this version of the ForEachCycleTag class:

import org.apache.taglibs.standard.tag.el.core.ForEachTag;
public class ForEachCycleTag extends ForEachTag {

I *did* try this version of halo.tld:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.0</jsp-version>
<short-name>halo</short-name>
<uri>http://halo.com</uri>;
<display-name>Halo library</display-name>
<description>Halo library</description>

<tag>
<name>forEachCycle</name>
<tag-class>com.halo.portal.struts.ForEachCycleTag</tag-class>
<tei-class>com.halo.portal.struts.ForEachCycleTei</tei-class>

combined with this version of the ForEachCycleTag class:

import org.apache.taglibs.standard.tag.rt.core.ForEachTag;
public class ForEachCycleTag extends ForEachTag {

***

The quoteSearch.jsp file contains this declaration:

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

***

With all of these versions (except for the original version which works, but not through NetBeans) I get the exception:

javax.servlet.jsp.el.ELException: Unable to find a value for "quoteStatus" in object of class "java.lang.String" using operator "."

To repeat a bit of evidence, when I use the "rt" library the function proprietaryEvaluate() gets called and I get the exception. With the "el" library I get where I want to go.

So that should address the questions about "JSTL 2.0" and whether my extension to the forEach tag is using the correct EL or RT declaration.

I'm thinking that my c.tld isn't a problem here, but rather my extension to forEach tag.
 
Bear Bibeault
Sheriff
Posts: 67750
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


That is where I get the "2.0" from...

<description>JSTL 1.1 core library</description>
<display-name>JSTL core</display-name>
<tlib-version>1.1</tlib-version>



The 2.0 in the xml processing tag refers to the JSP version. The above elements define the version of the contained tag library.

when I use the "rt" library



There is no rt library for JSTL 1.1. That's a JSTL 1.0 artifact.

javax.servlet.jsp.el.ELException: Unable to find a value for "quoteStatus" in object of class "java.lang.String" using operator "."



This indicates that somewhere you are referencing xyz.quoteStatus in an EL expression, where xyz is a String.
[ February 13, 2006: Message edited by: Bear Bibeault ]
 
Jerome Mrozak
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My quoteSearch.jsp file contains:


<halo:forEachCycle items="${quoteSearchForm.quotes}"
var="quotes" varStatus="loop"
begin="${quoteSearchForm.detailsStartIndex}"
end="${quoteSearchForm.detailsEndIndex}"
cycleId="cy" cycleItems="#D4D0C8 #BBBBBB">
<tr height="20" bgcolor='<c ut value="${cy}"/>' >
<c:choose>
<c:when test="${quotes.quoteStatus eq STATUS_OPEN}">

From the not-recent standard.jar c.tld file, which is included in the recent standard.jar as c-1_0.tld:

<tag>
<name>out</name>
<tag-class>org.apache.taglibs.standard.tag.el.core.OutTag</tag-class>

From the recent standard.jar c.tld file:

<tag>
<description>
Like <%= ... >, but for expressions.
</description>
<name>out</name>
<tag-class>org.apache.taglibs.standard.tag.rt.core.OutTag</tag-class>

So in the context of *this* conversation I wish to continue to refer to my problems as "el" library and "rt" library.

Now, I've recompiled my FourEachCycleTag.java file using the ".rt." package path and redeployed it with no good effect.

So I changed my halo.tld file to be:

<?xml version="1.0" encoding="UTF-8" ?>

<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">

<description>Halo library</description>
<display-name>Halo library</display-name>
<tlib-version>1.1</tlib-version>
<short-name>halo</short-name>
<uri>http://halo.com</uri>;
<tag>
<description>
An enhanced iteration tag, accepting a space-delimited
list of phrases (colors, etc.) that will be iterated
through as the items list is displayed. Use this for
things like different colors for each line.
</description>
<name>forEachCycle</name>
<tag-class>com.halo.portal.struts.ForEachCycleTag</tag-class>
<tei-class>com.halo.portal.struts.ForEachCycleTei</tei-class>
<body-content>JSP</body-content>
<attribute>
<name>items</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>com.halo.portal.quote.QuoteSummary</type>
</attribute>
<attribute>
<name>begin</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<name>end</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<name>step</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<type>int</type>
</attribute>
<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
<type>com.halo.portal.quote.QuoteSummary</type>
</attribute>
<attribute>
<name>varStatus</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>cycleItems</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>cycleId</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

</taglib>

What I changed was the "items" type (it was "java.lang.Object") and the "var" type (it didn't exist, presumably as java.lang.String). This follows a pattern from the (most recent) c.tld tag. But neither the "QuoteSummary" or "Object" versions of the declaration change anything.

So...the "quotes" reference is assumed to be a QuoteSummary (or QuoteSummary[]) in the "2.3" servlet version. In the "2.4" version the same code is assumed to be a String.

Still at a loss...
I get the feeling I'm repeating myself at people who are willing to help. I'm not wanting do dis anyone. But I'm guessing that updating from servlets 2.3 to 2.4 shouldn't be *this* hard. Is there really a FAQ on doing this?

Thanks,

Jerome.
 
Bear Bibeault
Sheriff
Posts: 67750
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

From the not-recent standard.jar c.tld file, which is included in the recent standard.jar as c-1_0.tld:



Once again, the rt library is for JSTL 1.0. In the Servlets 2.4/JSP 2.0 environment you should forget that it even exists.

Just backing up... would it not be simpler to just write your own tag based on javax.servlet.jsp.tagext.IterationTag rather than trying to piggy-back on a particular implementation of the forEach tag?
 
Jerome Mrozak
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(quack) (quack) (quack) (quack) (quack)

I got all of my ducks in a row and got success.

The first big thing here was changing my forEach extension to inherit from the ".rt." forEach used in my application (standard.jar).

The other big thing was to make my halo.tld to be a copy of the new c.tld, using only a variant of the ForEachTag section.

Finally, I made sure that all of my bits were pointing to the same combo of (NetBeans, Tomcat). Not mentioned in previous posts, and somewhat unaware by me, was that I was changing files *here* and running Tomcat on *there*. Grrr.

Anyways, I'd not have realized the impact of my having the wrong versions of my forEach tag extension.

Now, why am I extending ForEachTag instead of IteratorTag? Because I want the background of each line of my list to have a different color (such as red, blue, red, blue). So I added some parameters that amount to stepping through a list, one per iteration.

On demand I can post the source code for this. Trivial, but the details are already sorted out.

Thanks again,

Jerome.
 
Jerome Mrozak
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, bad explanation. I wanted to use the facilities of forEach, but I wanted only one change. So I inherited from that.

I didn't like the struts-el tags, or couldn't easily get <logic:iterate> to pass along the data constructs. I also had a bias to using the JSTL constructs.

Jerome.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So putting it simply, the problem was the custom tag which originally extended the JSTL1.0 forEach tag.
Once you updated from JSTL1.0 to JSTL1.1, you needed to update your custom tag to extend the JSTL1.1 forEach tag instead.

Finally, I made sure that all of my bits were pointing to the same combo of (NetBeans, Tomcat). Not mentioned in previous posts, and somewhat unaware by me, was that I was changing files *here* and running Tomcat on *there*. Grrr.


Frustrating I agree. Been there, done that.

Now, why am I extending ForEachTag instead of IteratorTag? Because I want the background of each line of my list to have a different color (such as red, blue, red, blue). So I added some parameters that amount to stepping through a list, one per iteration.


Fair enough I guess.

Couple of comments (just because)
Personally I would probably use style classes rather than hard coded colours like you seem to have done.

In fact I probably would have left the forEach tag alone and set the style/colour using the varStatus variable.
ie something like this. (taking advantage of the new ternary syntax, and the fact you can now use EL expressions outside of the JSTL tags...)



Just some thoughts.
Nice to hear you got it going.

Cheers,
evnafets
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic