You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ian Beaumont <IB...@categoric.com> on 2002/02/15 21:22:31 UTC

RE: Can this be done at all using Form objects within struts fram ework

I still don't get it.  I have been initialising my form bean values in the
reset method - clearly not the way intended.

A Simple example:  
I have a page that lists stock items.  On selecting an item the user is
taken to a different screen where they can edit the details for the selected
stock item (quantity, description etc).  If the user enters an invalid value
then the page needs to be re-displayed with the error and the values the
user entered.
I have a stock bean that represents the stock item returned from the
back-end system.

So how do I build the system?
On selecting the stock item from the list this calls the edit stock item
action.  At this point my validation form for the editing of a stock item
doesn't exist (I think) - and if it did, how would I get hold of it.
Therefore I can't populate the fields in the form bean from my stock bean
yet.  If I could get the form bean then wouldn't the reset method get called
when the browser changed to the edit stock item page - wiping out any values
I'd set.

Thanks
Ian

-----Original Message-----
From: theron.kousek@webmd.net [mailto:theron.kousek@webmd.net]
Sent: 15 February 2002 16:46
To: Struts Users Mailing List
Cc: struts-user@jakarta.apache.org; Kalven.Beaver@expressbill.com;
Huey.Tan@expressbill.com
Subject: Re: Can this be done at all using Form objects within struts
framework



thanks Ted:

Your recommendation is a great way of doing it.

Theron



 

                    Ted Husted

                    <husted@apach        To:     Struts Users Mailing List
<st...@jakarta.apache.org>        
                    e.org>               cc:

                                         Subject:     Re: Can this be done
at all using Form objects within struts 
                    02/14/02             framework

                    05:11 PM

                    Please

                    respond to

                    Struts Users

                    Mailing List

 

 




The form shouldn't preload the records. You should use an Action to
preload the records, put them on the form, and then forward to the JSP
when it's all said and done.

The form bean is part of the view. In a Model 2/MVC application, it
should not interact with the model/database.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/


theron.kousek@webmd.net wrote:
>
> With struts,when using a Form, I'd like to be able to have the form
> "pre-load" records prior to the form being displayed.
> Actually, more than just that, I'd like to have a form that can be
entered
> in 3 different possible states:
>
> - Insert state (in which case the form is empty)
> - Edit/View state (in which I "preload" the rows from the database)
> - Delete state (in which I "preload" the row from the database but have
the
> fields disabled).
>
> The validation() method is great because it contains a reference to the
> request object but I notice there is no "init()" or "preload()"
> method that comes with the form that I could "check/set a state and
> pre-load a row from the database" so that my getters would know
> to use the record.
>
> By writting a  constructor for the the form, I don't have access to the
> request object.
>
> How can this be done?     Is there a way to force the struts framework to
> call a method on my form object (to load/initialize values) prior to the
> form being displayed?
>
> thanks,
> Theron
>
> --
> To unsubscribe, e-mail:   <
mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <
mailto:struts-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <
mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <
mailto:struts-user-help@jakarta.apache.org>




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

Re: Can this be done at all using Form objects within struts framework

Posted by Ted Husted <hu...@apache.org>.
If a page needs to have its controls populated from the model, then the
input property should be an action that handles that population. The
action can then forward to the page to display the data. 

In between validate and the action, the controller would call reset and
populate the ActionForm. This usually doesn't matter, since the same
parameters are still in the request. 

Though, reset only clears the properties you tell it clear. The default
reset does nothing. If there is a property that is not set from the
request, then there is no point in clearing it. The reset method is
really only intended to clear checkboxes and other controls that might
not be cleared in a HTTP request. If request scope is being used, rather
than session scope, then reset isn't needed at all. 

So, you could move the code from the reset method in the ActionForm to a
"reset" action that did the same thing. This way the ActionForm (a view
object) is not bound to the backend system (a model object), and all the
interactions with the backend system is through Action classes
(controller objects). 


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/



Ian Beaumont wrote:
> 
> I still don't get it.  I have been initialising my form bean values in the
> reset method - clearly not the way intended.
> 
> A Simple example:
> I have a page that lists stock items.  On selecting an item the user is
> taken to a different screen where they can edit the details for the selected
> stock item (quantity, description etc).  If the user enters an invalid value
> then the page needs to be re-displayed with the error and the values the
> user entered.
> I have a stock bean that represents the stock item returned from the
> back-end system.
> 
> So how do I build the system?
> On selecting the stock item from the list this calls the edit stock item
> action.  At this point my validation form for the editing of a stock item
> doesn't exist (I think) - and if it did, how would I get hold of it.
> Therefore I can't populate the fields in the form bean from my stock bean
> yet.  If I could get the form bean then wouldn't the reset method get called
> when the browser changed to the edit stock item page - wiping out any values
> I'd set.
> 
> Thanks
> Ian
> 
> -----Original Message-----
> From: theron.kousek@webmd.net [mailto:theron.kousek@webmd.net]
> Sent: 15 February 2002 16:46
> To: Struts Users Mailing List
> Cc: struts-user@jakarta.apache.org; Kalven.Beaver@expressbill.com;
> Huey.Tan@expressbill.com
> Subject: Re: Can this be done at all using Form objects within struts
> framework
> 
> thanks Ted:
> 
> Your recommendation is a great way of doing it.
> 
> Theron
> 
> 
> 
>                     Ted Husted
> 
>                     <husted@apach        To:     Struts Users Mailing List
> <st...@jakarta.apache.org>
>                     e.org>               cc:
> 
>                                          Subject:     Re: Can this be done
> at all using Form objects within struts
>                     02/14/02             framework
> 
>                     05:11 PM
> 
>                     Please
> 
>                     respond to
> 
>                     Struts Users
> 
>                     Mailing List
> 
> 
> 
> 
> 
> The form shouldn't preload the records. You should use an Action to
> preload the records, put them on the form, and then forward to the JSP
> when it's all said and done.
> 
> The form bean is part of the view. In a Model 2/MVC application, it
> should not interact with the model/database.
> 
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Java Web Development with Struts.
> -- Tel +1 585 737-3463.
> -- Web http://www.husted.com/struts/
> 
> theron.kousek@webmd.net wrote:
> >
> > With struts,when using a Form, I'd like to be able to have the form
> > "pre-load" records prior to the form being displayed.
> > Actually, more than just that, I'd like to have a form that can be
> entered
> > in 3 different possible states:
> >
> > - Insert state (in which case the form is empty)
> > - Edit/View state (in which I "preload" the rows from the database)
> > - Delete state (in which I "preload" the row from the database but have
> the
> > fields disabled).
> >
> > The validation() method is great because it contains a reference to the
> > request object but I notice there is no "init()" or "preload()"
> > method that comes with the form that I could "check/set a state and
> > pre-load a row from the database" so that my getters would know
> > to use the record.
> >
> > By writting a  constructor for the the form, I don't have access to the
> > request object.
> >
> > How can this be done?     Is there a way to force the struts framework to
> > call a method on my form object (to load/initialize values) prior to the
> > form being displayed?
> >
> > thanks,
> > Theron
> >
> > --
> > To unsubscribe, e-mail:   <
> mailto:struts-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <
> mailto:struts-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:   <
> mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <
> mailto:struts-user-help@jakarta.apache.org>
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>