aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JavaBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JavaBean" Watch "JavaBean" New topic
Author

JavaBean

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
I think that I can create a javabean only whit properties id and type like this:
<jsp:useBean id="pref" tye="com.abc.Preferences"/>
But I found this question:
Assuming that com.abc.Preferences is not an interface or an abstract class and that 'pref' is not already instantiated in any scope, which of the given options correctly declare a useBean tag?
And <jsp:useBean id="pref" tye="com.abc.Preferences"/> is a bad option. Why?? I am wrong??
Thank you in advance.
[ April 18, 2002: Message edited by: Jordi Marqu�s ]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
only TYPE attribute is not sufficient..u also have to supply either beanName or class attribute
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
With only type-attribute you can only get allready instantiated beans
(for example instantiate the bean in a helper-class of the controller and assign it to the id variable in the jsp).
To instantiate a new bean, you need class or beanName also.
This sounds logical to me: To really instantiate an object you need the real class and type might be a supertype of the class of the object you want to instantiate.
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Hi,
When a page uses <jsp:useBean>, when does the bean get instantiated? At that line?
I am trying to use an overloaded constructor to set instance variables from the constructor. Am I allowed to do that with a bean, or will I need to call setters in the bean class?
Thanks!
g.
Jignesh Malavia
Author
Ranch Hand

Joined: May 18, 2001
Posts: 81
Originally posted by Garann Rose Means:
When a page uses <jsp:useBean>, when does the bean get instantiated? At that line?

Yes, the bean gets created at the point where the useBean tag occurs, provided
a) The bean with the specified id is not already present in the specified scope and
b) Either the class attribute or the beanName attribute is provided
Originally posted by Garann Rose Means:
I am trying to use an overloaded constructor to set instance variables from the constructor. Am I allowed to do that with a bean, or will I need to call setters in the bean class?

useBean action uses the default constructor. But you can initialize a newly created bean either by using the setter methods in a scriptlet or by using the setProperty action within the body of the useBean action
<jsp:useBean id="aBean" class="MyBeanClass">
<jsp:setProperty name="aBean" property="aProperty" value="aValue"/>
</jsp:useBean>
For a detailed explanation of the useBean, setProperty & getProperty actions, have a look at the sample chapter at http://www.manning.com/deshmukh/chap14.pdf Initialization is explained in section "Initializing bean properties" on page 262
HTH
-j
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Read it, you'll not regret if you do.
 
jQuery in Action, 2nd edition
 
subject: JavaBean