• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About jsp:useBean tag

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every body
I want to ask 2 questions
1-----If we have following lines in a JSP file
<jsp:useBean id="hello" class="SomeClass" scope="request"/>
<jsp:useBean id="hello" class="SomeClass" scope="application"/>
Is in 2nd tag new bean created?Please give some discription if convineant .What happen if scope attribute's value in both places are interchanged?
2-----It has been written in every book that if there is a bean object with same scope and the same id bean wont be created but existing bean instance will be assigned to same id.
Well my question is that(knowing the fact that bean id's becomes avaliable as local variable in _jspService() method ) if 2 use bean tags in the same page have same id but different scope then will 2 bean objects will be created and thus availlable in the same page by 2 local variables of same name(is it not illegal)
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand the question too well but I'd recommend not to have equal bean names in one JSP. I don't even think it's legal.
 
Fozan Zaidi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Alicea
but what about my first question in which two bean tags have same ids , same class but 2 different scopes.Will 2 bean objects of the same class be created with one id or one will be created or a compile time error will result?

[This message has been edited by Fozan Zaidi (edited December 03, 2001).]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi .
Well ,it is illegal to duplicate the id attribute on the same JSP file, but if you declare your objects on diffrent pages, a 2 objects with the same name and class will be declared , each one on it's own scope.for more benifit , see JSP 1.2 spesification.
Regards.
Maher.
 
Fozan Zaidi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Maher bhai but
If we have a bean object with application scope in some other jsp file and if we use a useBean tag in our current page with same id and class but any other scope (request,page or session)What will be the result.Please tell me what is gernal rule of thumb?
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can specify the same bean with different scope in another .jsp
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fozan,
Your question is valid. But you can not define two beans with the same name(id) in the same page. The method invocation on the bean instance goes by the bean name(id), you need a way to tell which instance's method to be invoked. Since a bean instance is an attribute within its scope, you can define two beans cooresponding to the same class for different scopes with different names, even in the same page, though this is definetely not a good design.
 
Fozan Zaidi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Ranchians
so concluding pt. is that we cant have 2 bean objects of any classes with same name(id)in the same page .We may have 2 bean objects of the same class with same id unless they are not in the same page and have not the same scope.
 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic