aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt with <jsp:useBean> having only type no class attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt with <jsp:useBean> having only type no class attribute" Watch "Doubt with <jsp:useBean> having only type no class attribute" New topic
Author

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

Isha Garg
Greenhorn

Joined: Mar 12, 2010
Posts: 29
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

Joined: Mar 12, 2010
Posts: 29
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.
Jan Skowronski
Greenhorn

Joined: Dec 21, 2007
Posts: 4
Oh! Thanks! If I only knew that weeks ago, so many sleepless nights;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt with <jsp:useBean> having only type no class attribute