• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Boolean Object in JSTL

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am a JSP, JSTL newbie and have really enjoyed
this forum!!

My question is I need to evaluate a Boolean object,
is there a way to do this?

This is what I thought would work and no dice:
<c:when test="${item.locked == 'true'}">

Thanks in advance for your help!



 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By enclosing the true in quotes, you've made a string out of it.

Rather, you can just use:



or



but the latter is unecessarily verbose.
[ August 02, 2005: Message edited by: Bear Bibeault ]
 
Chris Cornelius
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip, I ran the program and got this:

WARNING: CORE3283: stderr: javax.servlet.jsp.JspTagException: javax.servlet.jsp.JspException: An error occurred while evaluating custom action attribute "test"
with value "${item.locked}": Unable to find a value for "locked" in object.

When debugging the program I can see the Boolean value in the bean object.

What else could I be doing wrong?

Thanks again!!
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the signature for the property accessor for 'locked'?

It should be:

public boolean getLocked()
 
Chris Cornelius
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the bean method:

public Boolean isLocked()
{
return locked;
}
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if the EL evaluation is sensitive to the 'is' form of a boolean accessor. Try the 'get' signature and see if your life improves.
 
Chris Cornelius
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help!!

I went ahead and changed everything from
Boolean to boolean and the method to getLocked,
and it worked like a charm!

Chris
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad it's working for you now.

After doing some testing, what's weird is that apparently it was the return type of Boolean (rather than boolean) in conjunction with the is/get prefix for the accessor method that was tripping you up.

The following formats work as one would expect:



but this



generates the "Unable to find a value" error (at least under Tomcat -- Resin 3 returns a blank rather than throwing an error).

I'm not as familiar with the JavaBeans Specification as I am with the Servlets, JSP and JSTL specs, so I'm not sure exactly what precept the latter form violates.

I'm intrigued enough to investigate further...
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear for your efforts.

May be is works only with primitive boolean and get works with any. Just a thought.
[ August 04, 2005: Message edited by: Adeel Ansari ]
 
Chris Cornelius
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the useful info, I will definately use that
in future projects.

 
Always look on the bright side of life. At least this ad is really tiny:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!