Why should pre-populating a form be done in the preceding action? When you
want to display some dynamic info. say in a table you put a value bean in
the request or session and use bean:write etc to display. Why should the
same not apply to form beans? Why not use the value attribute of the the
html tag libraries to pre-populate the data? I have seen posts saying it
should not be done this way but no reasons are given. 

What I mean is:
<html:text property="data" value="<%=bean.getData()%>"/> is a valid way to
populate the form (as long as the bean is in request scope and not session
or application scope)

why is the above not recommended or preferred?

The only reason I can think of is that we have to use scriptlets in the
html:text and other tags because it is not possible to nest bean:write tags
with the html tags. But that is more of a limitation of struts taglibs and
not a design flaw(IMHO). And this limitation can be overcome by using nested
tags which have recently been integrated into struts. 

Also, having the pre-population done in the action involves moving
presentation code into the action which is more of a controller than a view.
Isn't this breaking the MVC? Also, when you look at the jsp page, which is
the view, you do not have any idea of where the data is coming from. 

Been trying to figure this out for some time now and I would really
appreciate it if someone can shed light on this.

PS: Sorry for the long post.

JC


-----Original Message-----
From: Barr, Scott [IBM GSA] [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 19, 2002 6:05 PM
To: 'Struts Users Mailing List'
Subject: RE: How do I init a Form bean via business logic?



Yes, calling an Action is the way to do this.
The struts-example shows how this is done.

Scott

> -----Original Message-----
> From: Chris Means [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, February 20, 2002 9:23 AM
> To:   [EMAIL PROTECTED]
> Subject:      How do I init a Form bean via business logic?
> 
> Hi,
> 
> If Form beans are supposed to be "distant" from the model, that means I
> probably shouldn't use the reset method of a form bean to populate it with
> data (other than blanks/defaults etc..).
> 
> So how do I set a form bean's properties prior to the form ever being
> displayed?
> 
> One suggestion has been to force a call to the forms' Action and check for
> a
> "submit" property on the form...if it's not there, then initialize it,
> otherwise, you're dealing with a submitted form.
> 
> Is this the best approach available?
> 
> Thanks.
> 
> -Chris
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>

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

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

Reply via email to