TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG-DEVEL:261] JSP and Bean constructors
Bob Tanner wrote:
>
> Is there a way instantiate a Bean from a JSP page that takes arguements?
No, only default constructors are allowed. This is because beans used
in JSPs must follow the JavaBean contract (empty constructors, implement
Serializable).
>
> <jsp:useBean id="foo" scope="session" class="foo.myBean" />
>
> Will instantiate myBean, using the myBean() constructor, what if I want to
> pass in a Properties class to the myBean contructor?
>
> myBean(Properties config)
>
> How can I do that with a JSP page?
Create the bean:
<jsp:useBean id="foo" scope="session" class="foo.myBean" />
and then call a method (like initialize) on the bean that takes a
Properties parameter right after the bean definition.
<% mybean.initialize(config); %>
--
Perry Hoekstra
---
"I don't see much sense in that," said Rabbit.
"No," said Pooh humbly, "there isn't. But there was going to be when I
began it. It's just that something happened to it along the way."