• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gizzmo Zeuzere
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to pass a parameter to JavaBean before call his constructor ?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes Thank
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic