• 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

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

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to pass a parameter to JavaBean before call his constructor ?
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes Thank
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic