Sri Sankaran wrote:
Yes! Finally someone who sees what I am talking about!
*That's* exactly the scenario I am talking about. I can't see how Struts can divine what values the form-bean property needs to be initialized. It is predicated by the preceding business logic.
Sri
-----Original Message-----
From: Martin Cooper [mailto:martin.cooper@;tumbleweed.com] Sent: Monday, November 11, 2002 9:40 PM
To: 'Struts Users Mailing List'
Subject: RE: [SIDEBAR] Form population (Was RE: request.setAttribute() for m confusion)
I think you missed the point here, Eddie (or perhaps I missed that you didn't miss the point :).
Think about it this way. Struts will create your form bean automagically in a couple of cases: when it needs to populate one from an incoming request, and when it needs to render a form but can't find the corresponding form bean.
Now consider the case where you need to populate the form with some values that the Action came up with somehow. You'd do that by having the values in the form bean properties, right? That way, the Struts HTML tags will do the work for you.
But now consider the case where you haven't yet invoked anything in the app that would cause the appropriate form bean to be instantiated. The action that came up with the values might have been invoked with a different form bean, or perhaps no form bean at all. So Struts hasn't instantiated the bean yet. Struts *will* instantiate the bean when it the <html:form> tag is processed, but by then, it's too late for the Action to populate the form bean.
So the only way for the action to pre-populate the form bean, so that those values are picked up by the Struts HTML tags to populate the form is for the action to instantiate the form bean itself.
One way of creating the form bean is RequestUtils.createActionForm().
--
Martin Cooper
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.
-- 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>

