Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Expression Language question

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from HFSJ Chapter 8, Page 429, Q19

Question:
An online jewelry retailer wished to customize their online catalog for users who are logged in. They want to show specials for the user's birthstone month. The company's special offers are stored as a Map<String, Special[]> identified as specials in application scope and updated daily.
There is a bean stored as a session-scoped attribute named userInfo. Calling getBirthdate().getMonth() on this bean will return the user's birthstone month.
Which of the following cope snippets could correctly retrieve the appropriate special offerings?
  • A. ${applicationScope[userInfo.birthdate.month.specials]}
  • B. ${applicationScope.specials[userInfo.birthdate.month]}
  • C. ${applicationScope["specials"].userInfo.birthdate.month}
  • D. ${applicationScope["userInfo.birthdate.month"].specials]}



  • I think both B and C are correct answers. What do you think?

    Note: Any typos please ignore, I have tried to keep this as type-free as possible and this question does not test on typos.

    Suhas.
     
    Ranch Hand
    Posts: 437
    Oracle Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi, Suhas.

    Here option C says, get the 'specials' attribute that is present in application scope, which is a map object. Then container checks is there 'userInfo' key present in map object. Here it is not available. It seems, Option C is wrong.
     
    Ranch Hand
    Posts: 48
    Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    In option B. ${applicationScope.specials[userInfo.birthdate.month]}, userInfo.birthdate.month results into the birthstone month of the user which is nothing but the key of a Map specials. So this expression returns the special offerings for the user.
    Consider option C. ${applicationScope["specials"].userInfo.birthdate.month}. Here the container looks for a key by name userInfo.But since the key to the Map is the user's birthstone month ,it will not find the specified key and hence doesnot return the special offerings.
    Thanks.
    Nitin.
     
    Suhas Wadadekar
    Ranch Hand
    Posts: 97
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Chinmaya and Niteen. I got it. Thanks for the explanation.
     
    Don't get me started about those stupid light bulbs.
      Bookmark Topic Watch Topic
    • New Topic