| Author |
How can I call a method named get() from EL?
|
Pat Farrell
Rancher
Joined: Aug 11, 2007
Posts: 4422
|
|
The Google Guava library has a nice addition, a wrapper class named Optional. You can use it as a return argument type when you might be returning a null value. Something llke:
The problem is that in the world of EL, a method that returns a value, has an implicit "get" prefix to the name, so you would take Java such as:
int tmp = foo.getValue();
and use
${foo.value}
What do I use when there is only the word "get", so there is no word "value" for EL to imply?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
It doesn't follow the JavaBeans conventions (silly google), so it's not accessible to the EL.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56233
|
|
|
P.S. The most modern version of the EL (Tomcat 7) allows general method calls I believe, but I haven't tested that myself.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
Bear Bibeault wrote:P.S. The most modern version of the EL (Tomcat 7) allows general method calls I believe, but I haven't tested that myself.
Yep. It may even be in JSF2 on Tomcat6. While I frequently and vocally discourage putting logic on View definitions, rules are made to be broken - providing you know what you're doing and the rules won't let you do it within the rules.
The normal EL POJO access is "#{bean.propname}" or "${bean.propname}" which will delegate to the BeanUtils getPropname(). But if you code "#{bean.get()}" it should invoke the bean's method that has the signature "public typename get()" or "public void get()" when rendering the View. You will have to have a way for "typename" to be automatically converted to a String via BeanUtils, though.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: How can I call a method named get() from EL?
|
|
|