On Fri, 22 Nov 2002, Martin Cooper wrote:

> Date: Fri, 22 Nov 2002 09:08:36 -0800 (PST)
> From: Martin Cooper <[EMAIL PROTECTED]>
> Reply-To: Struts Developers List <[EMAIL PROTECTED]>
> To: Struts Developers List <[EMAIL PROTECTED]>
> Subject: Re: pre-populated ActionForms / suggestion [patch] for beta1.1b2
>
>
>
> On Fri, 22 Nov 2002, Thomas Heller wrote:
>
> > [ posted to struts-user but i just realized struts-dev might be a better
> > place for this]
> >
> > Hi there,
> >
> > I'm trying to create a form with some pre-filled which either come from a
> > cookie or a database. i browsed the archive and found a comment from Craig
> > where he says the best way to do this is by routing the specified request
> > into a action and populate the form there. IMHO this way would complicate
> > the Actions execute method unnecessary complicat cause it must have a
> > "action-case" for "prepopulate".
> >
> > IMHO the best way to handle what i would want to do would be done like this.
> >
> > 1. introduce a "prepare(HttpServletRequest request)" method info
> > "ActionForm"
> > 2. invoke this method in "RequestUtils.createActionForm(...)" right after
> > "instance.setServlet(servlet)" in line 638
>
> I agree with Eddie that you really should be doing this work in an action.
> Even if you did have a prepare() method, this certainly isn't where you
> would want it to be called, and there's nowhere else Struts could call it
> that would make sense.
>
> The problem with calling it here is that I really don't think you want to
> be going through all the trouble of filling out the form fields right
> before Struts overwrites them with the parameters of an incoming request.
> Remember that form beans are created for you when a request comes in, and
> your prepare() method would be called then too.
>

I agree with Eddie and Martin that this is probably not a good idea, but
for a different reason -- it would violate the layering of the MVC model.

Remember that form beans are part of the View tier.  Adding a prepare()
method for the purposes you propose would typically involve interacting
with the model (getting stuff from the database, applying business rules
to decide what information to display, and so on.  That kind of thing
should really be done via an Action, which is why Struts encourages the
current approach.

> --
> Martin Cooper

Craig


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

Reply via email to