In a related question. . .

can one use multiple set methods without destroying the basic concept of a
bean. . ie


  private int value;

  public void setValue(int value) {
    this.value = value;
  }
  public void setValue(String value) {
    this.value = Integer.parseInt(value);
  }

or does this create problems for the "introspectiveness" (is that really a
word?) of the bean?

additionally, in this same case, can the getValue return a String as opposed
to an int?  or is it part of the requirement that the type T (below) is the
same?

  public TypeA getP()
  public setP(TypeA value)

or is it possible to have:

  public TypeA getP()
  public setP(TypeB value)

where TypeA and TypeB are different?

Thanks yet again,

Jeff



> -----Original Message-----
> From: Karl Roberts [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, December 07, 1999 9:11 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Bean constructors
>
>
> Hi,
>     One of the main concepts of a bean is that it must have a
> No-argument
> constuctor. The reason for this is obvious if you consider
> that a bean is supposed
> to be a self contained bit of code that a bean box can
> manipulate like any other
> bean. So in order to make sure that all beans behave the same
> way some conventions
> were adopted, ie all methods the retrieve the bean's properies are
>     public T getP()    methods
> all methods to set properties are
>     public setP(T value)   methods
>
> In order for all beans to be loaded in the same way (without
> knowing anthing about
> a bean but it's name) it was decided that the default no
> argument constuctor
> (which contains an implicit super() ) should be used.
>
> This said it is possible to have a bean which can take
> parameters in it's
> constuctor as long as you also have a no argument constructor
> (constuctor
> overloading ) but bear in mind if you let generic bean
> loaders load your bean they
> will always use the no-argument default constructor, but you
> can indeed write a
> scriplet in your JSP to instanciate your bean (class).
>
> eg
>
> public class MyBean {
>     private String name=null;
>     public MyBean() {
>         this.setName("World");
>     }
>
>     public MyBean(String name) {
>         this.setName(name);
>     }
>
>     public String getName() {
>         return(name);
>     }
>
>     public void setName(String name) {
>         this.name=name;
>     }
> }
>
> In this case if you use <jsp:useBean ...> the default
> constuctor will be used. But
> if tou use
>     <% MyBean testBean = new MyBean("Karl") %>
> then the other constuctor will be used. The thing is the
> <jsp:useBean ...> tag is
> a generic bean loader and has to have a standard method of
> launching all beans.
> The only thing I can sugest is for you to write your own
> special tag so your XML
> guys don't have to get their hands dirty ;-)
>
> Karl
>
> "Bailey, Jeff A" wrote:
>
> > Hi all,
> >
> > Was just wondering if there was a way to call a constructor
> other than the
> > default one using <jsp:usebean...>
> >
> > For example,
> >
> > // Default constructor
> > MyBean() {
> >   testVal = 0;
> > }
> >
> > // Something different
> > MyBean(int i) {
> >   testVal = i;
> > }
> >
> > I understand I can do something like this:
> > <%
> >   MyBean m = new MyBean(10);
> > %>
> >
> > but is it possible to call the constructor and pass it an
> argument (the int
> > i) while using the <jsp:usebean...>tags instead of using a
> get and set with
> > the default constructor.  This is a poor example because
> setTestVal(int i)
> > could be used easily, but for what I am working on, it
> would be much easier
> > to pass arguments to the constructor and also utilize the
> <jsp:usebean....>
> > tags so that our XML guys can work with it without too much
> instruction.
> >
> > Thanks for the help
> >
> > Jeff
> >
> >
> ==============================================================
> =============
> > To unsubscribe: mailto [EMAIL PROTECTED] with body:
> "signoff JSP-INTEREST".
> > FAQs on JSP can be found at:
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
>
> ==============================================================
> =============
> To unsubscribe: mailto [EMAIL PROTECTED] with body:
> "signoff JSP-INTEREST".
> FAQs on JSP can be found at:
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to