• Post Reply Bookmark Topic Watch Topic
  • New Topic

About jsp:useBean tag

 
Fozan Zaidi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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)
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • 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
  • 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).]
 
maher dabbas
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can specify the same bean with different scope in another .jsp
 
Frank Lin
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!