JSP EL -- Can't get ?: to work

J

javaguy

I'm using Tomcat 5.5.4 and Java 1.4.2. My web.xml specifies
http://java.sun.com/dtd/web-app_2_3.dtd.

I try:

<div id="something"
style='display:<c:eek:ut value="${myTest ? 'none' : 'inline'}"/>'>

and I get:

org.apache.jasper.JasperException: <h3>Validation error messages from
TagLibraryValidator for c</h3><p>
581: tag = 'out' / attribute = 'value':
An error occurred while parsing custom action attribute "value"
with value "${sampleOrderForm.hasAttachments ? 'none' : 'inline'}":
Encountered "?", expected one of ["}", ".", ">", "gt", "<", "lt",
"==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-",
"*", "/", "div", "%", "mod", "and", "&&", "or", "||"]
</p>

Since ?: is part of the EL, why won't it work here?
 
R

Rhino

I'm using Tomcat 5.5.4 and Java 1.4.2. My web.xml specifies
http://java.sun.com/dtd/web-app_2_3.dtd.

I try:

<div id="something"
style='display:<c:eek:ut value="${myTest ? 'none' : 'inline'}"/>'>

and I get:

org.apache.jasper.JasperException: <h3>Validation error messages from
TagLibraryValidator for c</h3><p>
581: tag = 'out' / attribute = 'value':
An error occurred while parsing custom action attribute "value"
with value "${sampleOrderForm.hasAttachments ? 'none' : 'inline'}":
Encountered "?", expected one of ["}", ".", ">", "gt", "<", "lt",
"==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-",
"*", "/", "div", "%", "mod", "and", "&&", "or", "||"]
</p>

Since ?: is part of the EL, why won't it work here?

I don't know JSP at all so this is strictly a wild guess: maybe the ? needs
to be escaped? Something like '/?' (without the apostrophes). There must be
a JSP reference manual or tutorial somewhere that would show an example that
included a '?' in it.

Rhino
 
R

Ryan Stewart

I'm using Tomcat 5.5.4 and Java 1.4.2. My web.xml specifies
http://java.sun.com/dtd/web-app_2_3.dtd.

I try:

<div id="something"
style='display:<c:eek:ut value="${myTest ? 'none' : 'inline'}"/>'>

and I get:

org.apache.jasper.JasperException: <h3>Validation error messages from
TagLibraryValidator for c</h3><p>
581: tag = 'out' / attribute = 'value':
An error occurred while parsing custom action attribute "value"
with value "${sampleOrderForm.hasAttachments ? 'none' : 'inline'}":
Encountered "?", expected one of ["}", ".", ">", "gt", "<", "lt",
"==", "eq", "<=", "le", ">=", "ge", "!=", "ne", "[", "+", "-",
"*", "/", "div", "%", "mod", "and", "&&", "or", "||"]
</p>

Since ?: is part of the EL, why won't it work here?
You aren't using JSP EL, as your subject states. You're most likely using JSTL
1.0 EL. That's where your problem lies. JSTL 1.0 EL doesn't support the ternary
operator to my knowledge.
 
J

javaguy

I understand that ?: is introduced in JSP 2.0. I thought that by using
Tomcat 5.5.4 I'd be getting that version of JSP. So, how do I convince
Struts to use JSP 2.0 EL? I think the answer would be to just use the
2.4 WEB-APP tag in the web.xml file. But when I do this I get goofy
Tomcat errors -- Attribute bundle doesn't accept any expressions.

I think perhaps I'm using "bad" or "old" versions of my c.tld, fmt.tld
files, but I don't see any of them in the Tomcat 5.5.7 download.
 
R

Ryan Stewart

I understand that ?: is introduced in JSP 2.0. I thought that by using
Tomcat 5.5.4 I'd be getting that version of JSP. So, how do I convince
Struts to use JSP 2.0 EL? I think the answer would be to just use the
2.4 WEB-APP tag in the web.xml file. But when I do this I get goofy
Tomcat errors -- Attribute bundle doesn't accept any expressions.

I think perhaps I'm using "bad" or "old" versions of my c.tld, fmt.tld
files, but I don't see any of them in the Tomcat 5.5.7 download.
Sorry for the delay, been out of contact. In your original post, you stated that
you were using the version 2.3 web.xml. By default, when using this, EL is *not*
evaluated in JSPs for backwards compatibility. Therefore, any EL evaluation you
were getting was from your JSTL tags, which would have to be version 1.0 since
version 1.1 doesn't actually evaluate EL, but rather relies on the JSP EL
evaluator. First, I'd recommend upgrading to JSTL 1.1 since it's made to work
with JSP 2.0. Then you'll have to upgrade to the 2.4 web.xml. There *may* be
other ways to enable EL, but I haven't researched those and this way is pretty
simple.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top