• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt with <jsp:useBean> having only type no class attribute

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reference: Chapter -8 Page 420 of new book and 416 of old book

I have following two classes


abstract class person with attribute name.
class Employee which extends Person with attribute empId.

I have following code in my servlet
Person p = new Employee();
p.setName("Evan");
request.setAttribute("personBean", p);

In my jsp I have:
<jsp:useBean id="personBean" type="com.example.Employee" scope="request">
<jsp:setProperty name="personBean" property="name"/>
</jsp:useBean>

Name is:: <jsp:getProperty name="personBean" property="name" />

If I run it, it works fine and displays Evan (which is expected according to me)

But the book at page 420 says, that it should fail at request time! The "personBean" attribute is stored at request scpde, so the <jsp:useBean> tag wont 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.

I dont understand why should it fail???
Am I doing anything different as it is not failing in my case??

One Point I noted is, In old book they have not specified any scope so it will by default search person in page scope so it should fail which is right,
but in new book they have specified scope="request" on <jsp:useBean> tag, so according to me it should not fail in this case.

 
Isha Garg
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aah.. I have got the errata for this at http://oreilly.com/catalog/errata.csp?isbn=9780596516680

Page 420
Answer for the number 1 exercise
ANSWERS 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 answer is wrong since the attribute scope is defined as request in the <jsp:useBean>. The correct would be "Prints Name is Evan."

Note from the Author or Editor:
VALID This exercise has dogged us from the beginning. It will be complete replaced in the next edition.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh! Thanks! If I only knew that weeks ago, so many sleepless nights;)
reply
    Bookmark Topic Watch Topic
  • New Topic