The important thing about ActionForm beans is that they are intended as
adapters between HTML forms and the rest of the application. If the
property is being used within a HTML form, then it is a valid use of an
ActionForm bean, regardless of whether the property is hidden or
immutable. 

It is not expected that there will be a 1:1 relationship between a HTML
form and an ActionForm bean. Some ActionForm beans may be used on
several forms, and several forms may use the same ActionForm bean. In
general, most people would design ActionForm beans to represent a
logical view (in the SQL sense) within the application. If the data is
being accessed by the same SQL query, then it would make sense to put it
all on the same ActionForm bean, regardless of whether it is exposed.

The only thing to watch for is Strut's calling reset() as part of the
validation. If a property is not present in the form, then it will be
reset, and your validation has to cope with that.

One caveat: ActionForms are not meant to be a panacea for the
presentation layer. There are often other JavaBeans in play on this
layer, with ActionForms being specialized for use with HTML forms.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel 716 737-3463.
-- http://www.husted.com/about/struts/


[EMAIL PROTECTED] wrote:
> 
> I have a Struts theory question on use of action forms versus java beans
> for read-only data.
> 
> We have extended workflow on our website such that the same form can look a
> bit different depending on where you are in the workflow.
> For example, the quote request will have limit and retention fields in the
> business request section.  Once you get to quote, those fields are
> read-only and there's an additional quote amount field.  When the client
> requests binder, all those fields are read-only and there is a checkbox.
> Once bound, everything is read-only.
> 
> There is some disagreement on the team as to how to handle this case.  We
> will obviously have four JSPs, one for each of these presentations.  The
> question is the data mapping to beans.
> 
> Half of the team feels that to use Struts in its purest sense, we need to
> have java beans that represent the read-only data, and action forms to
> represent the editable data.  That would mean four action forms, one for
> each JSP.
> 
> The other half of the team wants to re-use the same action form for all
> four cases, bean:define it in the session, and use bean:write to print out
> the data if read-only.  The major advantage is simplicity - we have one
> bean that represents all of the data - there is no need to understand what
> part of the workflow we are in when translating the data from the data
> model to the presentation layer beans.  It is also easier to understand for
> an HTML programmer or developer that the same bean is used regardless of
> whether it is a bean:write or any of the html tags.
> 
> We certainly don't want to end up in a position where we have broken the
> framework and hurt our extensibility in future releases.  The first
> scenario would seem to follow the framework more closely, but in this
> special case, is it a problem to deviate and use the ActionForm for what it
> is - a bean?
> We would appreciate any advice and experiences.
> Thank you.
> 
> Lisa Stephens
> GeneralCologne Re
> Trumbull, CT
> 203 328 5227

Reply via email to