• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Mock Exam 41

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mock exam question 41:

You are taking part in an initiative to remove scriptlets from the JSPs of a legacy web application for a major bank. You come across the following lines of code:
<% if (((com.yourcompany.Account>request.getAttribute("account")).isPersonalChecking()){ %>
Checking that fits your lifestyle.
<%}%>

How can you replace this user JSTL?
A. <c:if test='${account.personalChecking}'>Checking that...</c:if>
B. <c:if test='${account["personalChecking"]}'> ....</c:if>
C. <c:if test='${account['personalChecking]}'>.....</c:if>
D. <c:if test='${account.isPersonalChecking}'> ...</c:if>


The given answer from the book is A,B,C.
But I think it should be D.
And I think option D should be

D. <c:if test='${account.isPersonalChecking()}'> ...</c:if>
 
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
And I think option D should be
D. <c:if test='${account.isPersonalChecking()}'> ...</c:if>

Note that this book was written based on EE5 using EL v2.1.

In EE6 you can use EL v2.2 with the added feature method invocations with parameters.
 
Jack Freeman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although,

if you copied this straight from the test, then C won't work at all because of a syntax error:

C. <c:if test='${account['personalChecking]}'>.....</c:if> There is a missing single quote between g and ]

However,

if it was <c:if test='${account['personalChecking']}'>.....</c:if>

Then A, B and C are correct, because they are really just referencing the getter of a boolean member of the account class. (In other words, all three call the getPersonalChecking() method of the Java class named Account). Since you shouldn't create a member that is a verb (isPersonalChecking) and there is probably not a method named getIsPersonalChecking(), then option D doesn't really make sense. This isn't really that great a question, though. To be more simple, they could have just asked if the dot annotation and bracket annotation reference class members in the same way (which they do).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic