• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

useBean default scope

 
Daniel Spritzer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

On page 355 of HFSJ 1.4, it states "If you don't specify a scope in either the <jsp:useBean> or <jsp:getProperty> tags, the container uses the default of "page".

However, on page 360, it gives an example:
<jsp:useBean id="person" type="foo.Person" class="foo.Employee">
<jsp:setProperty name="person" property="*" />
</jsp:useBean>

and then describes the * as iterating through all the REQUEST scope parameters searching for a match to the bean's propteries.

Isn't this a contradiction? Shouldn't you have to specify the scope="request" in the useBean?

Thanks
Daniel
 
Daniel Spritzer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, on the same topic.. I'm assuming the "*" matches all the values based on the class, and not the type?

So for example, if foo.Person (the type) had only one property, but its child class foo.Employee (the class) had two properties, the * would search the request for TWO properties.
[ April 27, 2008: Message edited by: Daniel Spritzer ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't this a contradiction?

No. First of all, getProperty/setProperty have no scope attribute, so you can forget about it. What HFSJ says is that the default scope for useBean will be "page". That's all. The "*" in the "property" attribute of setProperty has nothing to do with this. What it does is look into the request parameters (not request scope parameters), and set the values in the bean. You are mixing request parameters and request attributes.

its child class foo.Employee (the class) had two properties, the * would search the request for TWO properties.

No, it's the other way around. The container uses the request parameters, and set their value into the bean, if possible. If you have a request looking like "/SetUser?name=bob&age=24", the container will try to call setName and setAge, using proper type conversion if necessary.
 
Daniel Spritzer
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent clarification. Thanks for the prompt response.

Daniel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic