• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exmulator mock exam question 66

 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
66
Marks: 1 Given a JSP page that contains the following code

<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<jsp:useBean class="com.examulator.userBean" id="user" />And given that userBean has a correctly defined setFirstName

Which of the following will set the firstName property of the userBean instance?

a)
<c:set target="${user}" property="firstName" value="marcus"/>

b)
<c:set property="firstName" var="user" value="elephant"/>

c)
<c:set target="user" property="firstName" value="marcus"/>

d)
<c:set id="user" property="firstName" value="marcus"/>

e)
<c:set id="user" target="firstName" value="marcus"/>

I thinks thre is no answer is for this question. but the mock exam shows answer is A.

can any one expalin how A is the answer for this question.

according to c:set rules "The target value of c:set must be eveluate to the actual bean object "
 
Srinivasan thoyyeti
Ranch Hand
Posts: 557
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,

I didn't get what doubt you have in your mind.

It looks high way for me. please state you query correctly.

it was given that UserBean is coorectly configured for to setFirstName.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The target value of c:set must be eveluate to the actual bean object

Then why do you think that ${user} is not the actual bean ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got two comments :
1. class="com.examulator.userBean" should be class="com.examulator.UserBean"
2. I'd be better to use <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> (JSTL 1.1)

If you don't mind, could you please try to contact the author about that ? Thank you.
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a lot for replay


<jsp:useBean class="com.examulator.userBean" id="user" />
in above statement the "user" is the ID of the UseBean

a)
<c:set target="${user}" property="firstName" value="marcus"/>

the same id (user) is using as a target="${user}". this is refering to the ID of the bean not to the actual object.

may be I understand the the question wrongly.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, "user" is referring to the id, but "${user}" is referring to the real bean.
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recommend writing the code and testing the code. Create the userBean class and directory etc etc. It's an excellent way to learn. You can check if the value has been set with the following JSTL code.

<c ut value="${user.firstName}"/>
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Marcus.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic