aspose file tools*
The moose likes Servlets and the fly likes Is it possible to pass a parameter to JavaBean before call his constructor ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Is it possible to pass a parameter to JavaBean before call his constructor ?" Watch "Is it possible to pass a parameter to JavaBean before call his constructor ?" New topic
Author

Is it possible to pass a parameter to JavaBean before call his constructor ?

Gizzmo Zeuzere
Ranch Hand

Joined: May 11, 2001
Posts: 45
Is it possible to pass a parameter to JavaBean before call his constructor ?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I strongly doubt it. A java object (which includes a bean) doesn't exist until it has been constructed, so there would be no object to call a method of. What do you want to do? perhaps there is another way to accomplish it.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by Gizzmo Zeuzere:
Is it possible to pass a parameter to JavaBean before call his constructor ?

I don't think u can do this with
<jsp:useBean tag.>
But ofcourse the bean class be instantiated inside the jsp as a normal java class. Infact if u don't've a zero arg constructor but have one which takes an arg, it will not be recognized as a bean by the JSP container. Hope others will correct me if i'm wrong.
karthik.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Yes. The java bean must have a no-arg constructor with 'public' access level. In useBean tag if an object with the scope does not exists a freash new instance is created by container by calling it's public no-arg consructor and assigned to the 'id' parameter in useBean tag. All these work happen in background by container.
regds
maha anna
Gizzmo Zeuzere
Ranch Hand

Joined: May 11, 2001
Posts: 45
Thank to all !
My problem was that I maked the operations in my constructor. So the parameter was passed after it was used. Now, I have a free constructor and a method who makes all the traitment.
thank
ajay gaur
Greenhorn

Joined: Dec 04, 2000
Posts: 16
Hi,
I think u want to use useBean action, but it instantiates only no arg. constructor beans & u want to initialise the variables in ur bean. U might do for this like:
<jsp:useBean id="beanID" code="beanClass" scope="scope">
<% beanID.init(pass parameter here); %>
</jsp:useBean>
For this u make an empty arg. constructor
bean(){
}
& a method
init(accept parameter here){
set the instance variables here
}
I hope this u need.
Ajay
Gizzmo Zeuzere
Ranch Hand

Joined: May 11, 2001
Posts: 45
yes Thank
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Is it possible to pass a parameter to JavaBean before call his constructor ?