> when a URL (myUrl.do) is invoced, the ActionServlet instantiates a
> myForm (according to the struts-config.xml), forwards control to a
> myAction object; the perform() method of myAction calls the reset()
> method of the myForm object and then forwards to a JSP page.

It is the JSP page itself that instantiates a myForm and calls the
reset() method. The ActionServlet can't do that because it doesn't
yet know which JSP page will handle the view. This is decided at
runtime by myAction. And since only the JSP page knows the URL to
which the form will be submitted, only it can know which bean needs
to be instantiated.

The exception to this is if your myAction object has already decided
during its perform() which JSP it will forward to. In this case,
it can create an instance of the form itself, fill in the form with
normal calls to the setter methods, and then save this form in
the request scope. So it looks something like:

        MyForm myForm = new myForm();
        myForm.setMyProperty("value");
        request.setAttribute("myForm", myForm).

Now that it is saved, your JSP page can access the values. You can
do this, for example, with:

        <html:form name="mySubmit">
            <html:text property="myProperty" size="10"/>
      </html:form>

There's still a problem here, though. You saved it under the name
"myForm" in the request scope. So how does <html:form> know
what name you used so that it can find it? It looks this up in the
struts-config.xml file which looks something like:

        <action path="/mySubmit" type="mySubmitAction"
            name="myForm" scope="request" validate="false"/>

In other words, it's the destination Action that determines which
form it wants to receive. And, by default, the JSP immediately
before it that instantiates the form. But you have the ability to
bypass this by creating one before JSP gets a chance to.

The one "gotcha" here is that JSP will still call reset() on the
form even if it didn't create it. So you need to write your
reset() method in such a way that it doesn't do anything if it is
being called by this JSP page.

Devon

Reply via email to