aspose file tools*
The moose likes JSP and the fly likes EL: how to access properties/methods that are not getFoo() methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "EL: how to access properties/methods that are not getFoo() methods" Watch "EL: how to access properties/methods that are not getFoo() methods" New topic
Author

EL: how to access properties/methods that are not getFoo() methods

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

I have a fair number of getters for boolean values/states that are named something like:

public boolean isActivated();

in EL, it expects that the methods are named starting with 'get' such as 'getIsActivated()'

What is best practice for letting EL access these methods?

I'd rather not add new entry points just to have

public boolean getIsActivated() { return isActivated();};

That feels like a bug farm to me.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

For Boolean properties, either getWhatever() or isWhatever() can be accessed with whatever.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

Cool, is that documented anywhere?

I find EL to be terribly frustrating, as the documentation is next to non-existant.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Pat Farrell wrote:Cool, is that documented anywhere?

It's part of the JavaBean conventions. It's not just an EL thing.

I find EL to be terribly frustrating, as the documentation is next to non-existant.

Actually, it has its own specification so it's rather extensively documented. However, I do find the EL Spec to be rather awful -- in Oracle's fervent desire to shove the abomination that is JSF down everyone's throat, they don't do a good job of pointing out what's valid for JSP versus JSF, making it seem much more overly complicated than it needs to be.

You might be better off looking at the JSP 2.0 Specification when the EL was still documented as part of JSP, and focused only on JSP. (But, of course, that won't include any changes made with JSP 2.1 and 2.2.)
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

I can't read Java specs, JSRs, from either Sun or Oracle. Perhaps there is actually information in them, but when I try to read them, all I see is blah blah blah

Every time I try to do a new construct in EL, be it a trivial IF/THEN/ELSE or a loop that isn't just over all elements in a list, it takes forever to find what the syntax is.

Writing a JSP page requires exact syntax of HTML, CSS, JavaScript, EL, each of which has unique syntax, options, and silly restrictions. Drives me nuts.

<end rant>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Pat Farrell wrote:Every time I try to do a new construct in EL, be it a trivial IF/THEN/ELSE or a loop that isn't just over all elements in a list, it takes forever to find what the syntax is.

Ah, you're mixing up the JSTL with the EL. The EL is simply the expression language; the tags are the JSTL.

The JSTL Spec is actually pretty good. Have you given it a try?

But I hear you about most Java Specs. The Servlet Spec and the JSTL Spec are pretty good. The JSP Spec, not so much. And some of the others may just have well been writing in Klingon for all the sense they make.

Writing a JSP page requires exact syntax of HTML, CSS, JavaScript, EL, each of which has unique syntax, options, and silly restrictions. Drives me nuts.

I'm a bit weird in that respect as none of that bothers me. I always seems to be held with a mix of admiration and bewilderment by my colleagues as they all just write Java (or C, in my current job) and can't understand how I can put up with using more than one language to get things done. To me, it's one of the things that keeps things interesting. I'd go nuts if I just wrote Java all day.

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4658
    
    5

Bear Bibeault wrote:Ah, you're mixing up the JSTL with the EL. The EL is simply the expression language; the tags are the JSTL.


Yes, you are correct. Should have been

"HTML, CSS, JavaScript, EL, JSTL, each of which has unique syntax, options, and silly restrictions"

But I seem to always be using EL in tags of JSTL controlling HTML or altering the ID/div so the CSS varies......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL: how to access properties/methods that are not getFoo() methods