Cheonsu, By definition bean constructors take no arguments. However, you
should be able to use the jsp:setProperty tag in conjunction with the
jsp:useBean tag to do what you want to do.

Say for instance that you have a FooBar class with a constructor that
takes string and date arguments:

  public FooBar(String user, Date date)

To make this a bean, you would need to add a constructor with no
arguments (or subclass it, if you don't have the FooBar source code. You
also need to add get/set functions for the init arguments to make them
accessible as properties:

public class FooBarBean extends FooBar {
  public FooBarBean() { super(null, null); // default value constructor
}

  public String getUser() { return mUser; }
  public void setUser(String value) { mUser = value; }

  public Date getDate { return mDate; }
  public void setDate(Date value) { mDate = value; }
}

Then, in your JSP, you should be able to use code like the following:

<jsp:useBean id="foobar" class="foo.bar.FooBar" scope="request">
  <jsp:setProperty name="foobar" property="user" value="me" />
  <% foobar.setDate(new Date()); %>" %>
</jsp:useBean>

The code between the useBean open and close tags will be evaluated only
when the bean object is created. I put a scriplet in to set the date,
because I think you can only use setProperty for properties that can be
represented as strings.

Hope this helps. Yours, JonTom

    JonTom Kittredge
    ITA Software, Inc
    Cambridge, Massachusetts

>If i want to initialize Constructor arguments.
>how to use bean tag ?

===========================================================================
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