This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

bean is in 'request' and searching property is in 'page'  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

On page 347 (and on other pages also) of HFS&J, the scope where we are searching for bean object (or where object will be created if not found) is request.

<jsp:useBean id=�person� class=�foo.Person� scope=�request� />

But while getting property, we are not specifying any scope, it means it is page scope (default one).

<jsp:getProperty name=�person� property=�name� />

Then how it is possible to get property, given that bean object is in other scope (that too in higher scope)?

Thanks.

[ May 22, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in getProperty, you refer to which bean you are using, right ? (name="person")
The useBean tag already specifies the scope where the bean is supposed to be, why would you need to specify a scope for getProperty ?
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

On page 347 (and on other pages also) of HFS&J, the scope where we are searching for bean object (or where object will be created if not found) is request.

<jsp:useBean id=�person� class=�foo.Person� scope=�request� />

But while getting property, we are not specifying any scope, it means it is page scope (default one).

<jsp:getProperty name=�person� property=�name� />

Then how it is possible to get property, given that bean object is in other scope (that too in higher scope)?


The container will try to find the value for the attrbute
named "person" from one of the scope mentioned below in the same order given below

page
request
session
Applicaton

so the bean object which is placed in request scope is retrieved by the container.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Parameswaran Thangavel:

The container will try to find the value for the attrbute
named "person" from one of the scope mentioned below in the same order given below

page
request
session
Applicaton

so the bean object which is placed in request scope is retrieved by the container.


Then why the <jsp:getProperty> action has scope attribute???

Thanks.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then why the <jsp:getProperty> action has scope attribute???


so that if u already knwo the scope, you put the scope and the container will get it from that, and will not have to search it through all the scopes. This will reduce the work the container has to do
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
???
Where did you see that getProperty had a scope attribute ?
There are only two attributes : name and property.

But while getting property, we are not specifying any scope, it means it is page scope (default one).

Why do you think that the default scope is set to page ? Did you read that in HFSJ ? Certainly not. getProperty has nothing to do with scope.
[ May 22, 2006: Message edited by: Satou kurinosuke ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
???
Where did you see that getProperty had a scope attribute ?
There are only two attributes : name and property.


Why do you think that the default scope is set to page ? Did you read that in HFSJ ? Certainly not. getProperty has nothing to do with scope.

[ May 22, 2006: Message edited by: Satou kurinosuke ]


From page 355 of HFS&J:

"If you don't specify a scope in either the <jsp:useBean> or <jsp:getProperty> tags, the container uses the default of "page"."
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks rathi.
According to the jsp specification, there is no scope attribute for getProperty.

Syntax:
<jsp:getProperty name="name" property="propertyName"/>


There's been a thread about this before:
http://www.coderanch.com/t/168940/java-Web-Component-SCWCD/certification/scope-attribute-HFSJ
[ May 22, 2006: Message edited by: Satou kurinosuke ]
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
Thanks rathi.
According to the jsp specification, there is no scope attribute for getProperty.

Syntax:
<jsp:getProperty name="name" property="propertyName"/>


There's been a thread about this before:
http://www.coderanch.com/t/168940/java-Web-Component-SCWCD/certification/scope-attribute-HFSJ

[ May 22, 2006: Message edited by: Satou kurinosuke ]


Thanks Satou.
So it's an error in HFS&J.
 
Peter Hu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:getProperty> is an method call that executes on a java bean. <jsp:useBean> creates an object. It needs to know where to store this object - defining its scope. Ideally <jsp:getProperty> should have a scope control, say only searches in certain scope. But it doesn't.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I agree that it's a "should", but the JSP 2.0 EL solves this "problem" by allowing you to specify the scope within which a reference to a scoped variable is made.

P.S. Please see my response in your other reply regarding your display name.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
I'm not sure I agree that it's a "should", but the JSP 2.0 EL solves this "problem" by allowing you to specify the scope within which a reference to a scoped variable is made.

P.S. Please see my response in your other reply regarding your display name.


It means, all the HFS&J examples (code) are wrong. Because there, the bean scope is request (most of the time) and scope in <jsp:getProperty> is not specified (so page)...
[ May 28, 2006: Message edited by: rathi ji ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and scope in <jsp:getProperty> is not specified (so page)...

No, not "so page".

Have you read the JSP Specification section on these actions?
[ May 28, 2006: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!