Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Initialize javabean constructor with parameter

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help! I am trying to initialize a bean by passing a parameter to the constructor. I need the scope to be "application". I know I have to have a zero arg constructor, but how do I have one that accepts paramters, and can be called from a JSP page?
Thanks so much!!!
------------------
Jen
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a useBean JSP tag, you can't invoke any constructor but the no-arg constructor. That leaves two avenues open: either you perform the initialisation in a setter method:Note that setFoo() is only invoked once, when the bean is instantiated - in general, the body of a useBean tag is evaluated only when the bean is instantiated.
Or you instantiate the bean outside a useBean tag:Subsequent pages can use useBean in the usual way to access the bean.
- Peter
 
Jennifer Johnson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Peter...I appreciate the alternatives! I've been trying to get the alternate constructor to work for days!
------------------
Jen
 
    Bookmark Topic Watch Topic
  • New Topic