2

Is there any way to access a field of a Java class using EL if a getter for that field does not exist?

For example, let's say I have a Java class with a field called foo. I know that if I also have a method in the class called getFoo() I can do this on a jsp page using this syntax:

object.foo

However, let's say getFoo() does not exist (and I have no way of creating it because I do not have access to the Java class). How then can I access the foo field using EL in my jsp?

skaffman
  • 398,947
  • 96
  • 818
  • 769
risingTide
  • 1,754
  • 7
  • 31
  • 60

1 Answers1

4

Is there any way to access a field of a Java class using EL if a getter for that field does not exist?

No. JSP EL is very strict in its requirement for javabean-compliant classes. You need a getter for your field.

Perhaps you can wrap the object in another class that does have a getter, and which fetches the field by reflection.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Yep you can use a Decorator object to decorate the object where you wish to obtain information from. :) – MalsR Apr 29 '11 at 19:34
  • It's an old answer but I'm still interested in how could this be done? – Kai Feb 19 '15 at 13:35