"Craig R. McClanahan" wrote:
> 
> John Hunt wrote:
> 
> > 1.What is the normal practice in the case where you
> > have two pages, and part of the input entered in the
> > first page needs to be displayed in the second page. I
> > would say use the same form bean for both the pages.
> > Any objections to this?
> >
> 
> This would also be the normal approach to a multi-page form -- all of
> the pages would share the same form bean, whose properties would be all
> the fields that appear on *any* of the pages.
> 
> The interesting part of this is knowing what to check in your validate()
> method, which will be called as each page is submitted.
> 

The way that I do this is as follows (we're still using Struts 0.5):
- in the action or a delegate of action, extract a list of parameters from the 
HttpServletRequest object
- attempt to map each of these parameters to a setter in the bean using reflection 
  (and call the setter)
- the above two steps produce a list of properties you can validate now

This gives you the flexibility of being able to move fields from one
page of a multi-page form to another without having to change any code.

There are some complications when validations on different fields need to
be performed with some coordination. Ordering can sometimes be important.
Essentially in the real world you don't have total flexibility in being
able to move around fields regardless of the underlying business logic.

> >
> > 2. When displaying readonly contents  on a page where
> > the contents were obtained by some processing done by
> > the Acton class which forwarded to this page, is it
> > advisable to put the output page's bean in session
> > scope and have the action class populate it ( or even
> > under request scope ). Or is it better to expose many
> > beans from the Action class that produced the data and
> > let the form bean get populated in the  jsp page ( for
> > the readonly attributes )? So these attributes
> > actually need not be propagated to the next action
> > class. Suggestions???
> >
> 
> I would not generally use the form bean for read only attributes --
> instead, I'd just create request or session attributes (depending on how
> long you wish to keep them) and use <bean:write> to display the
> read-only contents of those beans.  This works even when you are not
> inside a form, and you can have any number of beans accessible to
> <bean:write>, but only one form bean per form.
> 
> Craig

Reply via email to