At 12:16 PM -0400 7/12/04, Erik Weber wrote:
Joe, thanks for your opinion. You and Rick have convinced me to stay with one form page for add/update. I did this before in a non-struts app, and despite all the conditionals I ended up with, the ensuing layout revisions did make it worth it.

So, Joe, I am not using Dyna Forms, just plain old form beans. (I may refactor my DTOs/VOs and form beans into some base class because of all the shared fields, but for now, I'm getting a lot of use out of a bean generator I wrote). Are you agreeing then, that the best approach (currently) is to create an action for the view screen (in this case, the "update" form page), and in that action, obtain a VO and use the values from that to set the properties of the ActionForm? You are saying if I do this I need to explicity set a key to the form as a request attribute? (Somehow I assumed that the form already would be set as an attribute and that all I would need to do is modify the values of it).

When Struts calls execute(mapping ,form,request,response), the form that it passes in is determined by the "name" attribute of the ActionMapping. The name, of course, must reference a <form-bean> element, which determines the type.


The ActionForm specified in the ActionMapping is intended as the wrapper for request parameters, so only in limited cases will it also be of the correct type for the subsequent view. If the only request parameter your action needs is the ID of the VO object you'll retrieve for population, then you could probably get away with specifying the "view form" (or "output form") in the ActionMapping. It's just important to note that this isn't how Struts is designed, and that inevitably, you'll come upon a case where you need to pass in more input data and therefore really need distinct form-beans for "input" and "output".

I believe in letting consenting adults do what they please, and so if you understand this, I think you can do it safely. Some people are kind of purists and insist on having a form bean even for the single ID parameter which might be coming in to your action.

Getting back to specifics, Struts uses the "name" and "scope" properties of an action-mapping to pass form beans between the controller and the view. If your pre-view action and your form-submission action have the same values then everything should work out (with a possible exception if you are using "request" scope and use a redirect, which would cause the "controller request" to go out-of-scope before the view can be drawn using that data.

In the case when you can't use the same form-bean in your action and in the subsequent view and yet you want to pre-populate a form in your view, you simply must ensure that a form-bean of the proper type is placed in the proper scope under the proper name by your action (or by a Tiles controller, or by any other logic that can sneak in before the view is rendered).

Hope that helps!

Joe

--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn back; I'll know I'm in the wrong place."
- Carlos Santana


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



Reply via email to