Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL Doubt in HFSJ

 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An online jewelry retailer wishes 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 code 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}
Ans is B

Can anyone explain me the reason correctly..
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the question once again you will get your answer easily..

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.

1. There is a Map available called specials in application scope.
2. There a bean too in session scope called userInfo.
3. The bean object define 2 methods called getBirthdate(), AND getMonth().

All we need to do here arrange the above information to get the desire result.
lets start with option A ${applicationScope[userInfo.birthdate.month.specials]} , here specials is not a property of a bean so it does not resolve.

option B ${applicationScope.specials[userInfo.birthdate.month]} finds a specials map in the application scope by looking at applicationScope implicit object, and try to invoke the values based on the generated key.. here key is determined by the expression userInfo.birthdate.month
so it get the right result

Option C. ${applicationScope["specials"].userInfo.birthdate.month} again this option try to call the methods on the Map object , but these methods are part of userInfo bean declaration.

D. ${applicationScope["userInfo.birthdate.month"].specials} here userInfo and its properties are available in the session scope not the application scope.

I hope this will help
 
sravanthi pulukuri
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
applicationScope.specials[userInfo.birthdate.month]}
not putting the value in quotes means that it retreives the value of userInfo.birthdate.month as attribute??

correct me if iam wrong.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sravanthi pulukuri wrote:hi,
applicationScope.specials[userInfo.birthdate.month]}
not putting the value in quotes means that it retreives the value of userInfo.birthdate.month as attribute??

correct me if iam wrong.


Yes you are correct! it retrives the value of userInfo.birthdate.month as attribute??


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic