aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Expression Language question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Expression Language question" Watch "Expression Language question" New topic
Author

Expression Language question

Suhas Wadadekar
Ranch Hand

Joined: May 16, 2006
Posts: 95
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.
    Chinmaya Chowdary
    Ranch Hand

    Joined: Apr 21, 2008
    Posts: 432
    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.
    Patil Niteen
    Ranch Hand

    Joined: Dec 10, 2009
    Posts: 48

    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.

    SCJP 1.4, SCWCD 5
    Suhas Wadadekar
    Ranch Hand

    Joined: May 16, 2006
    Posts: 95
    Thanks Chinmaya and Niteen. I got it. Thanks for the explanation.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Expression Language question