• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL jsp:useBean question

 
Yasir Bajwa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Here is a small snippet of code from HFSJ pg 347

<jsp:useBean id="person" class="foo.Person" scope="request" />
<jsp:getProperty name="person" property="name" />

So here, the name property is set on the person bean in the request scope.

What if I have another person bean in a different scope? For example, if I tried something like:

<jsp:useBean id="person" class="foo.Person" scope="page" />
<jsp:useBean id="person" class="foo.Person" scope="request" />
<jsp:getProperty name="person" property="name" />

Does the id attribute in the useBean tag have to be unique? If so, then how can we reference beans
with the same name in different scopes? If I understand correctly, the getProperty tag cannot
indicate the scope its name attribute refers to?
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yasir,

The code that you have given should throw a translation error saying 'jsp.error.useBean.duplicate' if you are using tomcat. The reason is that bean with unique ids are allowed on a single JSP page. Here are two links with discussions on similar topic, may be you would like to go throught them Similar Post 1
Similar Post 2
Hope these are helpful to you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic