• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Question - Bean Standard Action

 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
which of the following useBean actions allow us to locate an existing bean object of MyBean class having the id theBean in the current session without creating a new instance if an existing instance is not available? select one chice.

Options:

1. <jsp:useBean id="theBean" type="MyBean" scope="session" />
2. <jsp:useBean id="theBean" class="MyBean" scope="session" />
3. <jsp:useBean id="theBean" beanName="MyBean" type="MyBean" scope="session" />
4. <jsp:useBean id="theBean" class="MyBean" type="MyBean" scope="session" />


without creating a new instance if an existing instance is not available?


This part of the question is pretty unclear to me. I appreciate if any one can explain it to me.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty confusing indeed

I think it should have said :
"Which of the following useBean actions allow us to locate an existing bean object of MyBean class having the id theBean in the current session", and stop here.
"without creating a new instance if an existing instance is not available" makes it all confusing. They wanted to insist on the "not create a new one".
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

They wanted to insist on the "not create a new one".


If thats the case then option 1 is correct.
 
P Chittaranjan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Option 1 is correct . Because it will try to find the object "theBean" in session scope. if It will not find the object,it can not create a object.
For creating the a new object we need either the "beanName" or "class" attribute along with the "type" attribute.

What I feel is, scince a type can be an Interface , <jsp:useBean id="theBean" type="MyBean" scope="session" /> This should fail to create a new object , if no object is there with that name.

Thanks
Chittaranjan
 
jim bop
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option one is correct imo. Its my understanding that both type and beanName are required attributes. Correct me if I'm wrong.
 
P Chittaranjan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,

You are right. Option 1 is correct. But "type" will work with the following combination.

1.type
2.type and beanName
3.type and class

So in the following question:

which of the following useBean actions allow us to locate an existing bean object of MyBean class having the id theBean in the current session without creating a new instance if an existing instance is not available? select one chice.

Options:

1. <jsp:useBean id="theBean" type="MyBean" scope="session" />
2. <jsp:useBean id="theBean" class="MyBean" scope="session" />
3. <jsp:useBean id="theBean" beanName="MyBean" type="MyBean" scope="session" />
4. <jsp:useBean id="theBean" class="MyBean" type="MyBean" scope="session" />


Option 1 will look for an existing bean in session scope. If it is there, use it.Otherwise it won't create a new bean object.

Hope, it will help you.

Thanks
 
Nicholas Way
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what does "beanName" do that "class" doesn't?
 
P Chittaranjan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.beanName attribute can refer to a serialized bean as well as a class. i.e if you have beanName="rancher.ranchedAddress.John" which is representing a serialized bean, the container will load the bean from rancher/rancherAddress/John.ser file. Here .ser is the extention for a serialized file.

Where as class attribute can only refer to the .class file.

2.beanName can accept request-time attribute expression.But class attribute can not.

Thanks
Chittaranjan
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice explanation Chittaranjan. Thanks.

I wish these notes where present in HFSJ.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic