aspose file tools*
The moose likes JSP and the fly likes JSTL c:if not working, but c:out is working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL c:if not working, but c:out is working" Watch "JSTL c:if not working, but c:out is working" New topic
Author

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

Ankush Bhargava
Greenhorn

Joined: Dec 03, 2004
Posts: 19
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

Joined: Jan 10, 2002
Posts: 61241
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankush Bhargava
Greenhorn

Joined: Dec 03, 2004
Posts: 19
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

Joined: Dec 03, 2004
Posts: 19
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

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61241
    
  66

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

Joined: Dec 03, 2004
Posts: 19
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

Joined: Dec 03, 2004
Posts: 19
oh, and this code runs just fine on my 3.0.14 version.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61241
    
  66

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

Joined: Jan 10, 2002
Posts: 61241
    
  66

Also, are you using Resin's builtin JSTL? Or a 3rd-party library?
Ankush Bhargava
Greenhorn

Joined: Dec 03, 2004
Posts: 19
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

Joined: Jan 10, 2002
Posts: 61241
    
  66

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

Joined: Dec 03, 2004
Posts: 19
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

Joined: Dec 03, 2004
Posts: 19
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

Joined: Jan 10, 2002
Posts: 61241
    
  66

Whew! I'm glad you got it working!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSTL c:if not working, but c:out is working