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

Accessing array using EL  RSS feed

 
O Affan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok heres the scriplet i am trying to avoid
balance.getUsers().getUser(0).getUserId();

Ok i am trying it with EL
${balance.users.user[0].userId}

and obviously it doesnt work because getUser(0) takes parameter and i am using user[0], but i dont know how to pass in arguments with EL to call getUser(0). Any idea?

Thanks
 
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
"affan181", please check your private messages for an important administrative matter.
 
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
What does getUser() return? Without letting us know what your code is doing, there's not much we can do to help you.
 
O Affan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getUser(int x) returns a User object which is a POJO. I don't know how to invoke getUser which takes an int as parameter with EL notation. I didn't find any examples. Is it possible? Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"O Affan",
Disregard my last post.
Thanks
-Ben
 
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
You are making a classic mistake of designing your data and then figuring out how to access it with the EL rather than designing the data to make the EL access easier.

Ask yourself, why does getUser() need to take an int as a parameter? Since we know that the EL cannot call general methods and pass parameters, what structure would serve the purpose better?
 
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
This article, though fairly old, addresses this issue.
 
O Affan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I am using old code that calls getUser(0) and i cannot change it! Oh well will have to use scriplets. Thanks for helping!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by O Affan:
Unfortunately I am using old code that calls getUser(0) and i cannot change it! Oh well will have to use scriplets. Thanks for helping!


Can you subclass it and then provide your own getter?
 
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
Or use a wrapper?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!