One of the definitions of a class being a 'bean' is that it have a
zero-argument
constructor (mostly so IDE's can instantiate them at design-time).
(In fact, at its most fundamental, this is all that is really required of a
class to be considered a 'Bean')

In most cases, you should be able to overload the constructor
method with the one you need that takes parameters.  You can
call the overloaded method within the zero-arg constructor or you can
just set all the necessary parameters via get...() methods and
then call your desired action method after constructing.

I would guess that this spec won't change.  Sun probably wants
future HTML/JSP editors to be able to instantiate & introspect javabeans at
design
time to aid design & allow coding helpers (such as the control-space
keystroke
used in Visual Age).  This would require zero-arg constructors.

hope that helps,

Steve

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Kevin Burton
Sent: Sunday, July 11, 1999 11:22 PM
To: [EMAIL PROTECTED]
Subject: <jsp:useBean> How do I use a constructor with parameters????


Why can't a developer provide a constructor with a parameter list?

<jsp:useBean id="test" scope="session" class="com.myCompany.test" />

Is is it just me or does this seem like a major pain.  If I want to use
a constructor with parameters I would have to write an initialize()
method and call it via:

<%
test.initialize("var1", "var2");
%>

IMO this just leads to bad code.  I am writing a bean that accesses an
Oracle database.  I would like to provde a database URL, logon and
password as part of the constructor.

Any ideas?  Is this slated to become a feature down the road?

Kevin

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to