Sri, pardon me, but I don't see how what you've said has anything to do with the point I was making. My sole point is that the actual creation (instantiation) of the form bean itself is a very mechanical act that Struts can perform on your behalf. There is no need to ever bother with creating a bean and placing it into some scope - just configure things properly and let it be done for you. Yes, you may very well need to initialize it's values in an action - but that is a seperate act from instantiation.

Why bother specifying a form-bean in your config file if you're going to create it yourself? Yeah there's some validation that can be done on it by Struts - but if you don't specify a form-bean for an action-mapping (you specify nothing for the action-mapping's name attribute) I don't believe that validation is done (why would it be? Struts doesn't know there's a form being used for this action!). Hrm - in fact you lose a great deal of the utility Struts provides if you don't make this association. Think about it: You have to tell Struts what type your form is of - so it can instantiate it. It needs this information for no other purpose. It could easily tell later on that the form is of the wrong type for validation etc. Also, you could specify by the attribute property the name of a form which you instantiated yourself. You *could* (if you wanted to) cut yourself off from the Struts form mechanism altogether.

What I suggest in no way impacts your ability to use good design (delegates etc). It just takes one very mechanical thing out of your hands - and out of your concern - and "just does it". It's solid. It works. If it ever fails you *please* file a bug! It also has no impact on where data comes from or where it goes to. You can pass data via a form from one action to another in about 2 ways that come to mind immediately: 1) session-scoped form 2) using hidden fields. I'm sorry, but I think you misunderstood my entire argument. My appologies for not having been clearer.

Sri Sankaran wrote:

While that is true, other than in the case of blank forms, isn't it true that one rarely depends on Struts to auto-generate the form bean? If you are presenting data, the form is pre-populated with such data. This data is typically derived by an earlier action -- mediated by a business delegate.
Say you have action-1 which is invoked when a page-1 is submitted. It does sundry business functions which includes getting the data necessary for the next page, page-2 say. In order for page-2 to pick up this data, action-1 must know the 'name' attribute for the action-mapping corresponding to page-2 and save the form-bean under this name in the appropriate scope.

Is there a way around this issue?

Sri
-----Original Message-----
From: Eddie Bush [mailto:ekbush@;swbell.net] Sent: Monday, November 11, 2002 3:00 PM
To: Struts Users Mailing List
Subject: Re: request.setAttribute() form confusion


You shouldn't ever have to create the form yourself if you:

- declare the form-bean in your config file
- use the name of the form you declared in the action mapping's "name" attribute

<form-bean name="myForm" ... />

...

<action path="/somePath" name="myForm" ... />

That should suffice. What you should find is that the form is created for you. Doing things as I mention simplifies you actions so that they can just expect the form to be there. If the form is not there you will probably NPE. That would indicate that you didn't create the association (by setting name="myForm") or Struts wasn't able to create the form for some odd reason.

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