Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in HFSJ question regarding EL?

 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On page 484, question 7, a code snippet that uses scriplets has to be rewritten using custom tags and EL.

snippet of snippet:

Answer B is the right answer according to the book:


If I'm not mistaken, beerService has to be an instance variable, that is declared somewhere else in the page with the <%! scripting element. It is not an attribute, otherwise beerService.getStyles() throws an exception.

But if isn't an attribute, and it certainly isn't an implicit EL object, then ${beerService.styles} will not work! The identifier left to the first dot in an EL expression has to be either an attribute, or an implicit EL object..

[ June 23, 2008: Message edited by: Jan Sterk ]

[ June 23, 2008: Message edited by: Jan Sterk ]
[ June 23, 2008: Message edited by: Jan Sterk ]
 
S Sravs
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is about the beerService.getStyles();
just remember and assume when ever you encounter "set" and "get" then there is bean class behind the scenes.
when any bean is instantiated in the current page the default scope is page.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is not the point. The thing is, if "beerService" is an attribute, the code should be like

(BeerService)(application.getAttribute("beerService")).getStyles()

If it is an instance variable, then the EL thing will not work.
[ June 24, 2008: Message edited by: Jan Sterk ]
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe Jan is correct. I did not review the spec, but if we can believe the book regarding EL, then beerService is a reference to an attribute. For the snipped to work the reference would have to have been initialized before the snippit.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have the full question, but the above snipets are obviously missing something.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic