• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

mock question regarding EL

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

Question 3. Given
<% Map m=new HashMap();
m.put(�m�,�n�);
m.put(�n�,�o�);
m.put(�o�,�p�);
pageContext.setAttribute(�map�,m, PageContext.PAGE_SCOPE);


Which of the following will output p ?
1.$ { map.o}
2.$ {map[�o�]}
3.${map.map.n}


Answer is given 1 and 2 . But I want to know why 3 is wrong?





Question 4.
Given
<% Map m=new HashMap();
m.put(�1�,�2�);
m.put(�2�,�3�);
m.put(�3�,�4�);
pageContext.setAttribute(�map�,m, PageContext.PAGE_SCOPE);


Which of the following will output 4 ?
1.${map.3}
2.${map[map[�2�]]}
3.${map[�3�]}
4.${map[map[2]]}


Answer is given 2 and 3 . But I want to know why 4 is wrong?


source ont know exactly from where i noted it
[ June 02, 2008: Message edited by: pradeep singh ]
[ June 02, 2008: Message edited by: pradeep singh ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 3:

I guess you are bit confused with the [] operator syntax in EL. The [] operator works by evaluating the innermost operations first. But the dot operator expects the right hand operator to be a bean property or Map key. So in this case, the map attribute don't have any key named "map", so its wrong.

Question 4:

Using an integer without quotes inside [] operator works correctly for List and Arrays. In case of Map and Beans, without quotes means, container tries to find the named attribute. In this case container tries to find the attribute named "2" and it fails.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ram,

ok then,why cant be 1.${map.3}(it is satisfies map properties right?)
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the . operator the thing that follows it should follow Java naming rules. 3 is not a proper Java name for an identifier.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Musab
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankx to you all speciallly to Ramkumar Rao
now i am clear about this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic