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

EL - accessing boolean property; is...() vs get...()

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Ranchers!

I have a DTO object which has few getters and setters. One of the properties is a Boolean and because the JavaBeans allows to create getter for such properties using the is...() form, I've used it. So I've got:



The point is that when I use in EL:



It shows that:

javax.el.PropertyNotFoundException: Property 'smoking' not readable on type java.lang.Boolean

When I change this invocation to:


it works fine (no suprise here).

So, is there some problem with is...() construction in EL?

I'm treating the business logic code as a black-box, so I am not able to fix any of its parts (talking about changing the getter and forgetting about the problem).

Thanks in advance for your help :-)

Cheers!
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Pedro,

I am not sure whether I understand your question well. I guess your class is like this?

You can access the smoking property of the bean Room with name "theroom" with EL like:


EL just looks for the getter getSmoking() (that should be defined public) and doesn't accept any parameters, so
is not possible

Regards,
Frits
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Frits!

Thanks for, as usual, fast reply :-)

Close one, but my getter is not as every other Java-type-getter, but uses "is" prefix (which is also valid from JavaBeans point of view and is more intuitive for me).

So, translating it to your example it's like:



Cheers!
 
Sheriff
Posts: 67746
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
Change from Boolean to boolean. The "is" form is only allowable for the primitive boolean type.

Oh, and ${room.isSmoking()} will not work. You cannot call methods on beans.
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear!

I didn't know that - in future I will remember that Boolean object should have "get" form.

And when it comes to ${room.isSmoking()}... well, it seems like working in my case:





and the result is

<td>true</td>



Tomcat 7 and:

Specification-Title: JavaServer Pages Standard Tag Library (JSTL)
Specification-Version: 1.1



-----------------

EDIT: well, now I'm a bit confused... I've added:



and.. it did work and set all values to true. It also works with


where rate is a String type property... What's going on?
 
Bear Bibeault
Sheriff
Posts: 67746
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
Can't test, I'm using Tomcat 6.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Goodmorning from here!

${room.setRate("250")}
where rate is a String type property... What's going on?


When you are running tomcat 7 you are dealing with EL 2.2 which adds support for method invocations.

Regards,
Frits
 
Bear Bibeault
Sheriff
Posts: 67746
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
Bingo!
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys! :-)

So, I guess it's time to finish the HF book and jump into the spec, as I can see the JSP 2.2 and EL 2.2 are part of JEE 6, so most likely they will be on the exam...

Cheers!
reply
    Bookmark Topic Watch Topic
  • New Topic