aspose file tools*
The moose likes JSP and the fly likes How can I call a method named get() from EL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How can I call a method named get() from EL?" Watch "How can I call a method named get() from EL?" New topic
Author

How can I call a method named get() from EL?

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

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: 60991
    
  65

It doesn't follow the JavaBeans conventions (silly google), so it's not accessible to the EL.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

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: 16012
    
  19

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I call a method named get() from EL?