Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Access ArrayList Attribute Elements in EL.  RSS feed

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Straight forward one.. I have an attribute which is ArrayList of POJOs (not beans). What is the EL version of loop and print the element info ( I have funcs like getName() etc etc. )


I cann't do a e. because they are not properties. I need to call functions..
e.getName() ??? Is this valid? like ${e.getName()} ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Time to bone up on what's a bean and what's not.

When you define an accessor such as getName(), you are defining a bean property.

So ${e.name} will work just fine.

What did you think a property was?
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya I know, feel embarassed. But it is definitely not a bean in its classic sense ( no public constructor, no setters not simple values etc). But you are saying if it has a getter, it is enough? I have one of them as java.util.Date so I can still say ${e.myDate) ?? May be date has internal toString but what about a complex object?

or is it simply that I really need to goback and read the rules on what can be next to the dot in EL ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Percival:
or is it simply that I really need to goback and read the rules on what can be next to the dot in EL ?


+1

You'll probably save yourself a lot of time if you just sit down and read the JSP spec cover to cover once, and then keep it on your desktop for future reference.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


+1

You'll probably save yourself a lot of time if you just sit down and read the JSP spec cover to cover once, and then keep it on your desktop for future reference.





There is a link in my signature.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as the accessors follow the bean pattern, you should be good to go. No public nullary constructor mean you can't instantiate the class usin jsp:useBean, but should not prevent you from accessing the properties.

You should get used to defining all objects that will be sent to a JSP as proper beans. Your life will improve.

Originally posted by Brian Percival:
I have one of them as java.util.Date so I can still say ${e.myDate) ?
The return type is moot.

but what about a complex object?
What of it? The reference will return the complex object. If you want to access properties deepr in the hierarchy, feel free:

${bean.this.that.the.other.thing}

or is it simply that I really need to goback and read the rules on what can be next to the dot in EL ?
Not a bad idea. The JSP Spec goes into detail.

Also, remember my advice about beans. If it's gonna be sent to a JSP, make it a bean!

(If you are dealing with a class that you have no control over, you can create a bean wrapper for it.)
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you both.. I will follow what you said. Have a great weekend.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!