• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in HFS ..in Script fre jsp chapter

 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
In Page 420 HFS there is a question :
<jsp:useBean id=”person” type=”foo.Employee” scope=”request” >
<jsp:setProperty name=”person” property=”name” value=”Fred” />
</jsp:useBean >
Name is: <jsp:getProperty name=”person” property=”name” />


What happens if the servlet code looks like:
foo.Person p = new foo.Employee();
p.setName(“Evan”);
request.setAttribute(“person”, p);

Its says:
The body will NEVER
run! It’s pointless to
put a body inside a <jsp:
useBean > tag if you have
only a type and no class!
Remember, the tag body
executes ONLY if a new
bean is created, which can
never happen when only
a type (but no class)
is
declared in the tag.


But Now since the person attribute is already present ,so when the beanid is checked it wil know that in request scope the person is there ,so there is no point in creating a bean , an dthrowing an error that class is not specified?


Thanks
Amarshi Mohanty
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an dthrowing an error that class is not specified?

Why should it throw an error ? If the person is already there, it will use it. If the person was not there, that would be a problem.
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the book says:
"FAILS at request time! The “person” attribute is stored at request
scope, so the <jsp:useBean > tag won’t work since it specifies only a
type. The Container KNOWS that if you have only a type specified,
there MUST be an existing bean attribute of that name and scope".
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the useBean tag uses scope="request". So it will look in the request scope, find the employee, and print its name. There seems to be some contradiction here. Did you check the errata ?
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:But the useBean tag uses scope="request". So it will look in the request scope, find the employee, and print its name. There seems to be some contradiction here. Did you check the errata ?



Well they missed....
but as per concept it shud not fail rite?.
thankx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic