Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean doubt??

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,

On page 348 of HFSJ, it says that the useBean can also create a bean if it can't find an attribute. So does this mean that it will write the bean class itself if we didn't write one?? If so where will that bean class get stored?? Confusing
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,



useBean can create a bean OBJECT. It will definetly not create or write a new class.
There is useBean's class attribute witch value specifies a bean's class to be instantiated in case of not finding an attribute.
HFSJ explains it quite clearly I think...
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also on the same page of the book, under the text that says "Turns into this code in the _jspService() method", I'm confused with the line

person = (foo.Person)_jspx_page_context.getAttribute("person", PaegContext.REQUEST_SCOPE)

Now in the jsp:useBean that is shown above this in the book, has the scope set to request...than how comes in the _jspService() method, the above code has _jspx_page_context.getAttribute(...), the one in bold in the above code??

Please clarify me ranchers...
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now in the jsp:useBean that is shown above this in the book, has the scope set to request...than how comes in the _jspService() method, the above code has _jspx_page_context.getAttribute(...), the one in bold in the above code??


I do not quite understand.

_jspx_page_context is a reference to PageContext. By PageContext you can read attributes from all scopes using an overloaded getAttribute(String, int) method.

The line you quoted tries to get "person" attribute from the request scope.
useBean tag at first tries to search for an attribute named by "id" in the specified scope. The line you quoted does the job.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jasiek,

I really didn't know that _jspx_page_context is a reference to page context...Where can I get such knowledge, I'm now on chapter7 of the head first book...Since, I didn;t know this, should I have to go back to previous pages and study anything again?? Please help me.
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have polish edition of the book so I cannot tell you to witch page you should skip exactly.
In the chapter 7 there is an example of the generated servlet class (based on counter jsp). There you can see what the _jspx_page_context is.

But you should not study it! It is Tomcat-specific. You do not have to know exactly how useBean is implemented, and you should NOT really care. All you must know is what useBean does, not how.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really didn't know that _jspx_page_context is a reference to page context...Where can I get such knowledge, I'm now on chapter7 of the head first book...Since, I didn;t know this, should I have to go back to previous pages and study anything again?? Please help me.


Go through the generated servlet code to get a clear picture....it should clear all your doubts...if you're using Tomcat you should find it at <TOMCAT diretory>/work/Catalina/localhost/<app-name>/org/apache/jsp
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jasiek Motyka.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic