• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About final mock exam question 3

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 3 of Head First final mock exam:


What is ture about AvatarTagHandler, assuming it extends SimpleTagSupport and outputs HTML that displays a user's avarta image?
Option A . The class should have a setter method called setSize.
...

I tried the AvatarTagHandler without setSize method:


If the tag never uses the size attribute, it still works.
Option A can be right or wrong.
Reason:
1. it should have setSize method in case the tag uses size attribute
2. it can still compile and work without size as long as the tag never uses size attribute.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the tag never uses the size attribute, it still works.

That is just luck. The specs require you to have a setter for each attribute.

From the JSP specs:

Lifecycle of Simple Tag Handlers
...
The attributes specified as XML element attributes (if any) are evaluated next, in the order in which they are declared, according to the following rules (referred to as "evaluating an XML element attribute" below).
The appropriate bean property setter is invoked for each.
...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic