• 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

JavaBean

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
only TYPE attribute is not sufficient..u also have to supply either beanName or class attribute
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read it, you'll not regret if you do.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic