Well, let's say (form == null) evaluates to true. Which is entirely possible if 
you don't specify a name (or attribute) attribute for the action element. 
However, that means that mapping.getAttribute() will also evaluate to null, 
right? If so, then I'm thinking that request.setAttribute and 
session.setAttribute will likely throw an NPE when they get invoked (or 
something else equally evil). So, it looks like it's not only unnecessary, it's 
just plain wrong. I'm guessing that the reason it works is that the only 
mapping for EditSubscriptionAction is this:

<action path="/editSubscription"
        type="org.apache.struts.webapp.example.EditSubscriptionAction"
        attribute="subscriptionForm"
        scope="request"
        validate="false">
  <forward name="failure" path="/mainMenu.jsp" />
  <forward name="success" path="/subscription.jsp" />
</action>

which has a value for the attribute attribute ;-) and so Struts will auto-
create the form.

Quoting Wendy Smoak <[EMAIL PROTECTED]>:

> EB> There is a contract between actions and the forms they use:  The form 
> EB> *will* be created.  This can be evidenced by the source (see 
> EB> RequestProcessor.java).
> 
> Dirk wrote:
> > Yes, the form does exist. As Reinhard wrote the NPE occurs
> > *inside* the validate methods. Seems like the validate methods is
> > using objects which do not exist.
> 
> Given the facts above, can someone comment on this code in the
> struts-example webapp?
> 
> from EditSubscriptionAction.java in the execute() method:
> 
>       // Populate the subscription form
>       if (form == null) {
>             if (log.isTraceEnabled()) {
>                 log.trace(" Creating new SubscriptionForm bean under key "
>                           + mapping.getAttribute());
>             }
>           form = new SubscriptionForm();
>             if ("request".equals(mapping.getScope())) {
>                 request.setAttribute(mapping.getAttribute(), form);
>             } else {
>                 session.setAttribute(mapping.getAttribute(), form);
>             }
>       }
> 
> Is that whole block just not necessary?  
> 
> -- 
> Wendy Smoak
> http://sourceforge.net/projects/unidbtags 
> 


-- 
Kris Schneider <mailto:kris@;dotech.com>
D.O.Tech       <http://www.dotech.com/>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to