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

jsp:useBean clarification please

 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

the below code displaying an exception saying, Attempted a bean operation on a null object.
what i understood was, object which created in sciptlet is not available for <jsp:getProperty>. that's fine. point noted.



the blow case is working fine, the object which created using jsp:useBean is available for scriptlet. I have no idea what's happenning here. why in this case it's working fine, i was expecting this to fail as well.



Could any one explain me why they are behaving so differently or did i miss any concept regarding this covered in HeadFirst.

Regards,
Ravi Kumar
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whats the problem??
the object created using <jsp:usebean> is available to the scriptlet code.

<jsp:usebean> not only creates an object in mentioned scope(page scope being the default)but also creates a local variable which is available to the translated servlet code.
[ May 11, 2008: Message edited by: Ash More' ]
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my question is how come jsp:useBean object is available to scriplet ? where as scriplet object is not available to jsp:getProperty ?
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Garla Ravi:
my question is how come jsp:useBean object is available to scriplet ? where as scriplet object is not available to jsp:getProperty ?
Because you need to bind the object into a scope first. For example:The only way for the tag to access an object is via a scope (page,request,session,application) - while useBean also happens to declare a local variable with the same name during translation. But it primarily works with scoped objects.

Ideally you don't need to use scriptlets at all since you can use only custom tags and EL:It's one of those things that once you've learnt how to use scriptlets, then you really shouldn't
[ May 11, 2008: Message edited by: Charles Lyons ]
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. got it
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh, well Charles Lyons replied to your query. cool.
infact for my scwcd exam i had read his book:
My views about the book:

1)After reading HFSJ, i had doubts about few topics. this book cleared my doubts very well.

2)very good coverage of API's, in fact i didn't look back at the API documentation after reading this book as this book became my reference to the API.

3)Good book to refer even after the exams (no noise, no fluff).

4)well, takes time to read,(going through HFSJ is a breeze, but this book takes time to finish, i just cant point to a single reason , maybe language is bit terse, maybe the no nonsense approach slows me down,maybe the pages are information packed,....).

5)Ah, didn't like the approach used for the custom tags chapter. reason being that, only partial code had been provided in the chapter and the author expects you to view the complete program from the downloadable code. don't like the constant juggling between PC and book.Plus i think the best material for custom tags is provided by SCWCD exam study kit which provides simple explanation and lots of 'complete' examples.

6)lots of questions at the end of each chapter. And they really test your knowledge about the chapter contents.Plus the book replicates the exam approach where code is often shown in a exhibit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic