Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Initialize javabean constructor with parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Initialize javabean constructor with parameter" Watch "Initialize javabean constructor with parameter" New topic
Author

Initialize javabean constructor with parameter

Jennifer Johnson
Greenhorn

Joined: Oct 27, 2001
Posts: 7
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


Jen
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Oct 27, 2001
Posts: 7
Thanks Peter...I appreciate the alternatives! I've been trying to get the alternate constructor to work for days!
------------------
Jen
 
 
subject: Initialize javabean constructor with parameter