This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt in EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt in EL" Watch "doubt in EL" New topic
Author

doubt in EL

raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
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

Joined: Mar 02, 2008
Posts: 169
Hi,

Any updates on this.

Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Patience is a virtue.


[My Blog]
All roads lead to JavaRanch
Abilash Ravindran
Greenhorn

Joined: Jul 04, 2007
Posts: 2
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

Joined: Mar 02, 2008
Posts: 169
Hi,

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

Thanks
Ranil Liyana Arachchige
Ranch Hand

Joined: Sep 20, 2008
Posts: 71

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


SCJP 1.4 (80%) , SCWCD5.0 (91%) , SCEA / OCMEA
gurneeraj singh
Ranch Hand

Joined: Mar 19, 2008
Posts: 80
Great Ranil!

You cleared lots of my doubts aswell.


SCJP 5.0 93%<br /> <br />SCWCD 5.0 97 %
raja ram
Ranch Hand

Joined: Mar 02, 2008
Posts: 169
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

Joined: Sep 20, 2008
Posts: 71

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

Joined: Mar 02, 2008
Posts: 169
Hi Ranil,

Thanks for the reply all my doubts are cleared now.

Thanks
Ranil Liyana Arachchige
Ranch Hand

Joined: Sep 20, 2008
Posts: 71

You are welcome!

Regards,
Ranil
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: doubt in EL