Actually I am starting to think this is appropriate behaviour.  After I sent
the original e-mail I realized that the ActionForm was NOT being
instantiated by Action1; in struts-config Action1 simply pre-populated some
beans and then forwarded to JSP2.  It was when JSP2 was being rendered that
I was seeing the 'reset' method for the ActionForm being called.  Diving
into the FormTag code, I found the following:

    public int doStartTag() throws JspException {

        // Look up the form bean name, scope, and type if necessary
        this.lookup();

        // Create an appropriate "form" element based on our parameters
        StringBuffer results = new StringBuffer();
        
        results.append(this.renderFormStartElement());

        results.append(this.renderToken());

        ResponseUtils.write(pageContext, results.toString());

        // Store this tag itself as a page attribute
        pageContext.setAttribute(Constants.FORM_KEY, this,
PageContext.REQUEST_SCOPE);

        this.initFormBean();

        return (EVAL_BODY_INCLUDE);

    }

    /**
     * Locate or create the bean associated with our form.
     * @throws JspException
     * @since Struts 1.1
     */
    protected void initFormBean() throws JspException {
        int scope = PageContext.SESSION_SCOPE;
        if ("request".equalsIgnoreCase(beanScope)) {
            scope = PageContext.REQUEST_SCOPE;
        }
        
        Object bean = pageContext.getAttribute(beanName, scope);
        if (bean == null) {
            if (type != null) {
                // Backwards compatibility - use explicitly specified values
                try {
                    bean = RequestUtils.applicationInstance(beanType);
                    if (bean != null) {
                        ((ActionForm) bean).setServlet(servlet);
                    }
                } catch (Exception e) {
                    throw new JspException(
                        messages.getMessage("formTag.create", type,
e.toString()));
                }
            } else {
                // New and improved - use the values from the action mapping
                bean =
                    RequestUtils.createActionForm(
                        (HttpServletRequest) pageContext.getRequest(),
                        mapping,
                        moduleConfig,
                        servlet);
            }
            if (bean instanceof ActionForm) {
                ((ActionForm) bean).reset(mapping, (HttpServletRequest)
pageContext.getRequest());
            }
            if (bean == null) {
                throw new JspException(messages.getMessage("formTag.create",
beanType));
            }
            pageContext.setAttribute(beanName, bean, scope);
        }
        pageContext.setAttribute(Constants.BEAN_KEY, bean,
PageContext.REQUEST_SCOPE);
    }

The doStartTag has a call to initFormBean; in initFormBean there is a call
to RequestUtils.createActionForm, followed by a call to the ActionForms
'reset' method.  In a wizard type of application, this could indeed cause
problems where the reset method may be clearing values from the ActionForm;
I've had to add code to a couple of my projects to check the mapping to see
if I wanted to reset or not.  Maybe one of the guru's could shed some light
on why the <html:form/> tag would instantiate the ActionForm and call reset
when the JSP is rendered, opposed to doing this when the form is actually
submitted....



Jerry Jalenak
Team Lead, Web Publishing
LabOne, Inc.
10101 Renner Blvd.
Lenexa, KS  66219
(913) 577-1496

[EMAIL PROTECTED]


-----Original Message-----
From: Richard J. Duncan [mailto:[EMAIL PROTECTED]
Sent: Thursday, June 19, 2003 12:00 PM
To: [EMAIL PROTECTED]
Subject: RE: ActionForm 'reset' method being called when JSP is rendered


If what your saying is true, it would break a *lot* of applications that
create/reuse an ActionForm in a particular scope and then forward to a page.
I wonder if something else is happening in your app. Just a thought...

Regards,
 
Rich

-----Original Message-----
From: Paul Harrison [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 19, 2003 11:43 AM
To: Struts Users Mailing List
Subject: Re: ActionForm 'reset' method being called when JSP is rendered

I am writing an application with a series of "wizard" type pages, so I 
thought that I would use one big ActionForm in session scope and each 
page add extra information to it - however this did not work as reset 
was being called at each page invocation - I am interested to hear that 
reset should only be called at instantiation time, because I believe 
that in 1.1 RC2 it is being called more often  than that - I can did out 
the old verision of the code to have a look at the exact circumstances 
if necessary....

Ted Husted wrote:

> In Struts 1.0.2 and later, reset is called by the html:form tag *if* 
> the ActionForm is being instantiated at that time. The scope shouldn't 
> matter.
>
> Also remember that the html:form tag is looking at the Action to which 
> it submits, which may not be "Action 1". If these are the same Action, 
> or share the same formbean under the same attribute, then the 
> ActionForm should already exist, and reset should not be called.
>
> -Ted.
>
> Jerry Jalenak wrote:
>
>> I'm seeing some odd behaviour with one of my actions.  If anyone can 
>> explain
>> this I'd sure appreciate it....
>>
>> Here's what I've got - in struts-config I have an ActionForm that is 
>> shared
>> by two Actions.  The ActionForm is created in session scope by the first
>> action, and referenced by the second Action (also in session).  
>> Tracing the
>> calls to 'reset' and 'validate' I see the following:
>>
>>     JSP is displayed  -> html form is submitted -> 'reset' is called ->
>> 'validate' is called -> Action 1 is performed -> forward to next JSP ->
>> 'reset' is called -> JSP is displayed
>>     
>> /\/\/\/\/\/\/\ !
>>
>> My understanding is that 'reset' should not be called again until the 
>> form
>> on the second JSP is submitted.  Have I completely mis-understood how 
>> this
>> works?  Or is it something due to the ActionForm being created in 
>> session
>> scope?
>>
>> TIA!
>>
>> Jerry Jalenak
>> Team Lead, Web Publishing
>> LabOne, Inc.
>> 10101 Renner Blvd.
>> Lenexa, KS  66219
>> (913) 577-1496
>>
>> [EMAIL PROTECTED]
>>
>>
>> This transmission (and any information attached to it) may be 
>> confidential and is intended solely for the use of the individual or 
>> entity to which it is addressed. If you are not the intended 
>> recipient or the person responsible for delivering the transmission 
>> to the intended recipient, be advised that you have received this 
>> transmission in error and that any use, dissemination, forwarding, 
>> printing, or copying of this information is strictly prohibited. If 
>> you have received this transmission in error, please immediately 
>> notify LabOne at the following email address: 
>> [EMAIL PROTECTED]
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>

-- 
Paul Harrison

[EMAIL PROTECTED]
tel: 0161 428 2794
mob: 07904025192



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


This transmission (and any information attached to it) may be confidential and is 
intended solely for the use of the individual or entity to which it is addressed. If 
you are not the intended recipient or the person responsible for delivering the 
transmission to the intended recipient, be advised that you have received this 
transmission in error and that any use, dissemination, forwarding, printing, or 
copying of this information is strictly prohibited. If you have received this 
transmission in error, please immediately notify LabOne at the following email 
address: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to