• Post Reply Bookmark Topic Watch Topic
  • New Topic

some help in EL

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
my web application contains a very simple bean like :

my JSP page creates an instance of this bean, like this :
<jsp:useBean id="cart" ........... />
${pageContext.cart.total}
well, I got the expected value, but I'm surprised !
AFIAK, EL is used to access (or simplify) bean's property, but my bean doesn't contain a property called total, just a method.
please correct me if I'm wrong :
when we use EL with JavaBeans, EL uses the get method, something like :
${bean.total}
here, the bean should has a method named getTotal( ), but it is unnecessary that this bean contains a property called total, right ?
would someone shed some light here ?
thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are mistaking the term property with the term field.

By exposing a getTotal() method on your bean, you have created a read-only property named total.

You might want to brush up on the JavaBean specification before delving into the EL.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A property to an outside class is just a combination of getXxx, setXxx, and/or isXxx methods. How you handle them internally is up to you.

A readonly property only has a getXxx or isXxx, a setonly property only has a setXxx. The isXxx returns a boolean.

The methods could return an instance variable, they could calculate a value, read from a database, call another method from another class (wrapper pattern). It' doens't matter.

If you want to read more on the subject, do a Google search on 'encapsulation'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!