Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarification for answer on JSTL

 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For all those following the HFSJ book. I need your help to understand the answer for question 4 on page 486 from the chapter Using JSTL

The correct choices are B and D.

I disagree, because "customer" is the name of the bean object "Person".

From what I've read using c: set target, the target must point to the actual object and not the name. This is the difference from c: set var.

I would agree it is B and D, if it was Person instead of Customer.

Can someone please explain.
 
Cristiano Sganzerla
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post the question !!!
 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JavaBean Person has a property called address. The value of this property is another javaBean Address with the following string properties: street1, street2, city, stateCode and zipCode. A controller servlet creates a session-scoped attribute called customer that is an instance of the Person bean.
Which Jsp code structures will set the city property of the customer attribute to the city request parameter? (choose all that apply)

A: $(sessionScope.customer.address.city = param.city}

B: <c:set target="${sessionScope.customer.address}" property="city" value="${param.city}" />

C: <c:set scope="session" var="${customer.address}" property="city" value ="${param.city}" />

D: <c:set target="${sessionScope.customer.address}" property="city" >
${param.city}
</c:set>
[ August 20, 2007: Message edited by: Arnab Sinha ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I've read using c: set target, the target must point to the actual object and not the name. This is the difference from c: set var.

In both answers, target is pointing to an actual object of type Address. It's not pointing to a name.
 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris, but here is my confusion

:sessionScope.customer.address

Not sure how target can determine what is customer, if it needs the actual object. Customer is the name of object/bean Person.

so I would have liked to see sessionScope.Person.address

Maybe I'll need to write a small app to figure this out.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arnab wrote:
Thanks Chris, but here is my confusion

:sessionScope.customer.address

Not sure how target can determine what is customer, if it needs the actual object. Customer is the name of object/bean Person.

so I would have liked to see sessionScope.Person.address

Maybe I'll need to write a small app to figure this out.


Arnab lets go see it step by step

"sessionScope.customer" - here we say return me an object bound to session scope with name customer. just like session.getAttribute("customer")

Now using reflection i can determine the type of the class.

Now the last part is ".address"

It is something like invoking getAddress in the bean returned in the first step. So target now has the instance of the Address class,

Other two attributes property and value will be used on this object thats is Address.

Now you said, you would have liked to see
sessionScope.Person.address

What will happen if i have two Person instances bound in session scope with different names?

Does that solve your problem?
 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Amol I realize my mistake. I appreciate the time you took to explain.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amol for the step by step explanation.
[ August 23, 2007: Message edited by: Christophe Verre ]
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome
 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1) PLease asssit me explaining two bean by coding to understand this example?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic