• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't test, I'm using Tomcat 6.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bingo!
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic