This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean possible error in HFSJ

 
thomas jacob
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exercise in the HFSJ book is as follows

The STANDARD ACTION:
<jsp:useBean id="person" type="foo.Employee" >
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>

SERVLET CODE:
foo.Employee p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

Question: What will the output for this be
<jsp:getProperty name="person" property="name" />

Answer in Book: The book states that this work fine and prints out Evan. The code inside the body of <jsp:useBean> will never run, since we specified a type without class.

I FEEL: IT SHOULD FAIL AT REQUEST TIME cos when the scope is not mentioned in the useBean tag, so it defaults to the page scope. When only the type is mentioned in the useBean tag there should be an existing attribute bean with the same name and scope. Here the scope is not same. The attribute bean exists in the request scope. The tag is searching in the page scope

The book anyhow contradicts the answer by saying when only the type is mentioned in the useBean tag there should be an existing attribute bean with the same name and scope

JAVARANCH GUYS PLEASE HELP....

Regards
Thomas
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep this thought came across my head but i brushed it aside and and continued with the book. The scope attribute should have mentioned "request".
 
Doyle Matt
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup Thomas, you are correct. Tried it out and I got an exception
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is where the head first gets clumsy
i have borken my head over this page as it has got an errata
but even after this the THING isnt yet clear, so i too BRUSHED the page aside and continued further
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's there in the errata

http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic