You web application uses a lot of Java enumerated types in the domain model of the application.
Built into each enum type is a method, getDisplay(), which returns a localized, user-oriented string.
There are many uses for presenting enums within the web application, so your manager has
asked you to create a custom tag that iterates over the set of enum values and processes the
body of the tag once for each value; setting the value into a page-scoped attribute called,
enumValue. Here is an example of how this tag is used:
10. <select name=’season’>
11. <t:everyEnum type=’com.example.Season’>
12. <option value=’${enumValue}’>${enumValue.display}</option>
13. </t:everyEnum>
14. </select>
You have decided to use the Simple tag model to create this tag handler.
Which tag handler method will accomplish this goal?
A.
public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
pageContext.setAttribute(“enumValue”, value);
getJspBody().invoke(getOut());
}
} (Exception e) { throw new JspException(e); }
}
B.
public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
getJspContext().setAttribute(“enumValue”, value);
getJspBody().invoke(null);
}
} (Exception e) { throw new JspException(e); }
}
C.
public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
getJspContext().setAttribute(“enumValue”, value);
getJspBody().invoke(getJspContext().getWriter());
}
} (Exception e) { throw new JspException(e); }
}
D.
public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
pageContext.setAttribute(“enumValue”, value);
getJspBody().invoke(getJspContext().getWriter());
}
} (Exception e) { throw new JspException(e); }
}
Explanation: