• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in EL

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In chapter 8 HFSJ Q1 is said as incorrect syntax. Why is it wrong.as per my understanding in this case hobbies will be treated as a attribute and since question says we have parameter
hobbies it is still a valid attribute, but when i tried to execute the code it printed nothing what actually is the reason. Can any body expalin this in more detail.

In chapter 8 HFSJ Q15 is said to be correct. But is wrong why is this. I think params is a map so this will not cause any problem.In case of objects which is actually a List a will be past as an index to List and it should not cause any errors is that correct?

if not can any body explain what actually is the problem here.

Thanks
[ October 01, 2008: Message edited by: raja ram ]
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Any updates on this.

Thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Patience is a virtue.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thinks thats because paramValues is an EL implicit object which would carry paramaters (not attributes) in the request scope. Since EL is user friendly when treating null, you wouldnt see an exception as such.

Regards,
Abilash
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can any body throw some more light on this topics. it will be really help full.

Thanks
 
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raja,

It is obvious that you can use EL expression with all Standard J2SE collection types , Arrays and also Pojo beans.

In the case of collection types Map , List have a slight difference in accessing their content in the containers. In Maps you have to follow [key,value] approach. Which means in Maps you always put a value against a key and when you want to retrieve the values you have to use keys to access them

key1 -------> value1
key2 -------> value2
...
...
keyN -------> valueN

this key, value both could be objects. most often String values are used as keys in Maps in real scenarios. so accessing a map could be done ${myBean["mapName"].someKey}
ex: ${myBean["params"].key1} , ${myBean["params"].key2},....,${myBean["params"].keyN}

In the case of List object all you have is "index" and a value bound to that index.Hence you access List values as ,

index1 ----> value1
index2 ----> value2
index3 ----> value3
-------
-----
indexN ----> valueN

The index value must be an int and value could be an Object. Because of that you can access List using EL expressions only using index values.

${myBean["listPropertyName"][indexvalue]} indexvalue could be int or a String which can legally be parsed in to an int value.

ex: ${myBean["objects"][0]} , ${myBean["objects"][1]},....,${myBean["objects"][N]}

are correct , but ${myBean["objects"].a} is incorrect since there is no index value as "a".

I hope this would help you a bit!

Regards,
Ranil
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great Ranil!

You cleared lots of my doubts aswell.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranil,
Thanks for the reply it is really very help full and i understood the concept.but in case of first question.


the index is a valid integer,even then it is not printing the value.I think
this is happening because when we say [hobbies] this has to be a Attribute in any one of the four scopes; but in this case this is not a attribute but a Parameter passed in a query. hence it is not working is that correct?

Thanks
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raja,

About ${paramValues[hobbies][0]},

paramaValues is a Map containing String[] objects. For and example suppose there is a query parameter named "myparam=abc" , in that case paramValues Map would contain a String[] object referred by the key "myparam". So when you say ${paramValues["myparam"]} it would refer to a String[] object. And this String [] object must have "abc" as its' value at the 0th index location.If you try ${paramValues["myparam"][0]}, this would show you what is in 0th index position of that String[].(In this case EL takes "myparam" as the name of the key)

Now suppose you access this without those two quotations in the expression. ${paramValues[myparam]} , in this case EL tries to evaluate myparam and it would look for an attribute bound to any of four scopes with that name. If it doesn't find any then it evaluates to null. Since EL is "null friendly" it doesn't throw and error, but would show nothing either. So even if you try to move up the object graph by writing ${paramValues[myparam][0]} you would not get anything as the output.

hope this resolves your problem.

Regards,
Ranil
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranil,

Thanks for the reply all my doubts are cleared now.

Thanks
 
Ranil Liyana Arachchige
Ranch Hand
Posts: 71
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are welcome!

Regards,
Ranil
 
reply
    Bookmark Topic Watch Topic
  • New Topic