Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL c:if not working, but c:out is working

 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am migrating from Resin 3.0.14 to Resin 3.1.0. Everything seems to work fine, except for inconsistencies in JSTL - All jtsl 'if' tags are not working!

example:
adding this to my JSP -
<cut value="${sessionScope.userSession.sessionValid==true}"/>

outputs a value of 'true' or 'false' based on the value of the variable 'sessionValid' in the 'userSession' bean in the HttpSession object.

but -
<c:if test="${sessionScope.userSession.sessionValid==true}">
<cut value="${sessionScope.userSession.sessionValid}"/>
</c:if>

does not work. and neither does -
<c:if test="${sessionScope.userSession.sessionValid!=true}">
<cut value="${sessionScope.userSession.sessionValid}"/>
</c:if>

I dont get any output from the JSP as all.

Clear JSTL is working, but only partly! I tried using c:choose, but even that did not work :-(
What could i be doing wrong?

TIA
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can test to see if <c:if> is working in general (as I'm usre that it is) with a small JSP file such as:



If you see "true" on the browser, <c:if> is working.

What remains is to debug your test expression.

[Added: don't forget to declare the JSTL in your page]
[ April 05, 2007: Message edited by: Bear Bibeault ]
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, thanks for you reply.

I tried the code snippet you gave, and the output was -
"${result}"

so i tried:


and i got -
false

what next?
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, thanks for you reply.

I tried the code snippet you gave, and the output was -
"${result}"

so i tried:


and i got -
false

what next?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Well, you can test to see if <c:if> is working in general (as I'm usre that it is) with a small HTML file such as:


Did you mean a small ".jsp" file or does Resin support JSTL in files with HTML extensions?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoopsy. Of course it's a JSP. My bad.

I've gone back and fixed the typo...

Ankush, my apologies. Please be sure that it's a JSP file and re-run to see the results. And don't forget to declare the JSTL c library in your page.

Good catch Ben!
[ April 05, 2007: Message edited by: Bear Bibeault ]
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey no worries. I did try running the code on a JSP and not an HTML.

Infact here's exactly what i ran -


output -
false | true


I've tried many combinations of values inside the c:if tags and none seem to work.
cut always works.
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, and this code runs just fine on my 3.0.14 version.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you don't use the <cut>?

Do you still get ${result}?

If so, your web app is not configured to enable the EL in template text and it must be for the JSTL 1.1 to work properly.

What does your web.xml look like? It must declare the app as Servlets 2.4 rather than 2.3. See the JSP FAQ for details.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, are you using Resin's builtin JSTL? Or a 3rd-party library?
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. When i don't use the cut, I get back what I wrote. i.e. the output is -
${result}

2. Resin documentation says that default is JSTL turned on. So i haven't played with that part.
How can I toggle it?

3. web.xml -
<web-app xmlns="http://caucho.com/ns/resin"
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"
version="2.4">


4. I guess I'm using the Resin's built in JSTL, as I did not explicitly add any JSTL jar file to the build.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankush Bhargava:
1. When i don't use the cut, I get back what I wrote. i.e. the output is -
${result}


This is an issue. Does it work in your Resin 3.0 installation?

Until you get this working, all other bets are off.

We're using Resin 3.0.17 so I don't have a 3.1 installation to test against.

2. Resin documentation says that default is JSTL turned on. So i haven't played with that part.
How can I toggle it?


It's not the JSTL that's an issue but the EL. For some reason EL in template text is not being evaluated and it must for the JSTL to work correctly.

3. web.xml -


Hmm, that looks ok.
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm, i see what your point.

I also tried running this against a Resin 3.0.23 installation. And that din't work either.
Now i am beginning to think if my configuration is not messy...?

Any tips on getting EL to work?
 
Ankush Bhargava
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally found the cause -
The build file had a 'resin-web.xml', and that skipped my sight. I added the namespaces
' xmlns="http://caucho.com/ns/resin" xmlns:resin="http://caucho.com/ns/resin/core" ' to the web-app tag and presto! EL started working.

Thanks for your help bear. Appreciate it!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whew! I'm glad you got it working!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic