Is it possible to pass a parameter to JavaBean before call his constructor ?
Gizzmo Zeuzere
Ranch Hand
Joined: May 11, 2001
Posts: 45
posted
0
Is it possible to pass a parameter to JavaBean before call his constructor ?
Frank Carver
Sheriff
Joined: Jan 07, 1999
Posts: 6913
posted
0
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.
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
posted
0
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
posted
0
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
posted
0
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
posted
0
yes Thank
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Is it possible to pass a parameter to JavaBean before call his constructor ?