Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Exmulator mock exam question 66

 
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 "
 
Ranch Hand
Posts: 558
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • 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 VI Editor Ubuntu
  • 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 VI Editor Ubuntu
  • 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.
 
arch rival
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.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic