Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this answer right?

 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Book - HFSJ
Chapter - 8
Page - 430
Question - 11

Which are true about the <jsp:useBean> standard action?

A. The id attribute is optional.
B. The scope attribute is required.
C. Then scope attribute is optional and defaults to request.
D. Either the class or type attributes may be specified,
but atleast one.
E. It is valid to include both the class attribute and the type attribute, even if their values are NOT the same.

The answer ticked was D and E.
Is it right?
I think only the option E is write.
Please clear my doubt.
 
Dilshan Edirisuriya
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D is also right. You have to use either type or class. But when you are using beanName attribute you have to use type and it's mandetory.
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't we use both class and type attribute in a <jsp:useBean>?

I am sure D is Wrong.
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D is not wrong at all.
Read the chapter again, your answer is there.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah...D is correct....go htrough the topic once again and I hope your doubt will be cleared
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They have specified it as either type or class may be specified and atleast one.They have not told that both cant be used together.I hope I am clear.

either both
or one but atleast one
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Radhika, i got it
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either the class or type attributes may be specified, but atleast one.

But it is really a foolish statement,isn't it?
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means that ..

1) if type is only declared..then the bean must already be there
we cannot create a new bean if it doesnt exists with only type mentioned
2) if class is only declared it is fine whether bean exists or needs to be created
3) if both are there,it is fine..
Same as above
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any possibility of someone using class attribute twice like :-

<jsp:useBean id="person" class="foo.Person" class="foo.Person"/>

then why they are saying "atleast one"
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sreeraj G H:
Is there any possibility of someone using class attribute twice like :-

<jsp:useBean id="person" class="foo.Person" class="foo.Person"/>

then why they are saying "at least one"


"At least one" does not mean "one or more class attributes", it means "a class or type attribute, but at least one of them". Thus, more than one class attribute would be incorrect.
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read the question carefully

Which are true about the <jsp:useBean> standard action?

A. The id attribute is optional.
B. The scope attribute is required.
C. Then scope attribute is optional and defaults to request.
D. Either the class or type attributes may be specified,
but atleast one.
E. It is valid to include both the class attribute and the type attribute, even if their values are NOT the same.



"At least one" does not mean "one or more class attributes", it means "a class or type attribute, but at least one of them". Thus, more than one class attribute would be incorrect.


MY POINT IS OPTION D IS WRONG.BECAUSE WE MAY USE TYPE AND CLASS TOGETHER.
AM I RIGHT?
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone give explanation of option D with a small example.
please...............

Because my mind says its a wrong statement.
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can use <jsp:useBean ....> without type or class using beanName.
Till chapter they are not specified about beanName property.Maybe because of that option D is correct.
 
Siddharth Purandare
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Here is the extract from the Hanumant singh's book. Its very properly defined there please have a look and let me know if you guys can understand this:::

With <jsp:useBean> we can use attributes as below:

A. id which is mandatory.
B. scope which is optional
C. We can use 4 combinations only with the below 3 attributes:
(i) Class
(ii) Type Out of (i)and (ii) atlease 1 is mandatory.
(iii) class and type
(iv) beanName and type

These are the only valid combinations!!! I hope this solves all the doubts and also it will be a good information to share with all you guys. Make a note of this.

Cheers!!!
 
Anitha Srinivasan
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sreeraj here u go,

<jsp:userBean id="name" scope="page|request|session|application" beandetails />

id - mandatory
scope - optional , default page

beandetails

class ="classname"
class="classname" type="typename"
beanname="beanname" type="typename"
type="typename"

type - superclass, interface, class
class -fully qulified name(package), Must not be a abstract class
beanName - name of a bean , attribute can refer to a class

Here is the coimbination,

1. beanName and class can't be together.
2. Atleast one of type and class MUST be present.
3. type can be alone or in combiantion with class or beanName

4.If type is used without the class, the bean must be present, else InstantiationExcpetion is raised if the object is not found.
If the the object is in wrong class ClasscastException raised.


I think i am clear , Pls correct me if some one has more points.

Thanks,
Anitha
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok now i am clear.
We must use atleast type or class property with <jsp:useBean ..>.
My thought was, we can use <jsp:useBean > with the combination beanName & id property.
But now i am clear that we can use beanName property only with type property.

Thanks for all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic