My opinion: Yes, you're right - it isn't necessary. My guess is that the particular piece of code you're looking at has existed there for some time and has yet to be updated.

The general idea is that if you tell Struts the action requires a form, and the form isn't there when you go to use it, either you have a misconfiguration (you didn't really tell Struts you needed the form, or it couldn't create it for some odd reason) or Struts has a bug. In either case, it's nice to have the feedback as quickly as possible - so you don't code to anticipate it not being there. Instead, you just let it NPE and then track down your misconfiguration or file a Bugzilla report.

Now ... Struts just does this for the form-bean specified in the config file, so, if you have a given page that requires multiple forms, you may need to resort to creating the unspecified forms yourself.

... would be nice if Struts could take multiple form-beans and handle them all for you. Moreover, using multiple forms in any single action is probably the exception rather than the rule, so it may not be useful enough to warrant having it in Struts (I would imagine this is why it's not there). If this came to be a common requirement that didn't have a good, clean solution, I'm sure Struts would start supporting it.

Wendy Smoak wrote:

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?

--
Eddie Bush




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