Hi Mattias,
The form bean is designed for easing the coding for moving of data from action
class to HTML form & vice versa.
Has any-one got a good case for doing anything else?
Keith.
--- Struts Newsgroup <[EMAIL PROTECTED]> wrote:
> Subject: Re: Design question on loading form data
> From: Vic Cekvenich <[EMAIL PROTECTED]>
> ===
> Here is sample pseudo code illustrating for one approach in
> action/perform. Call for the model bean to populate in the action's
> perform. Maybe the code of that retrieval and anything else having to do
> with data is in the model bean. I sometimes use the FormBean, with
> getters and setters, and put a retrieve, update, insert, delete methods
> in the bean, so model is in one place, should there be any bugs.
> Also, you can create such a bean, and test it in just a normal servlet,
> before putting it in Struts. You could also test or use that bean anyplace.
>
>
>
> package app;
> public class NameLstAct extends baseAct {
> public ActionForward mperform( ActionMapping mapping,
> ActionForm form,HttpServletRequest request,
> HttpServletResponse response)
> throws IOException, ServletException {
> // if list
> sf=(SearchFrm)session.getAttribute("SearchFrm"); // get the arguments
> String fn= sf.getFstName();
> String ln= sf.getLstName();
> NameLstFrm nl = new NameLstFrm(); // make the Form Bean
>
> nl.dbCon(); // ask bean to get a connection from the pool
>
> // get us a list of names; based on retrieval argments
> nl.retrieve(fn,ln);
> //obviously, the FormBean has the SQL command coded in the above method
>
> nl.dbDisCon(); // we do not need the connection no more
>
> return(mapping.findForward("nameLstPg"));
>
> // if save
> // {nl.validate(); nl.update(); ... }
> // if delete {nl.delete(); ...}
> // if new/insert {nl.inset(); ...}
> }// perform Act
> } // end of code.
>
>
>
>
> Mattias Norlander wrote:
>
> > Hello!
> >
> > If i want to fill a form with data (from, say a database) before showing
> > it to the user: Can this be done in reset() method of the form, or should
> > it be in the perform() method of the action class?
> >
> > I think that doing it in the reset() method produces the cleanest code.
> > This can be done in quite a dynamic way too, since the reset method has
> > access to the http request and the mapping. It can use these to get info
> > on what (if any) item to load from the database.
> >
> > Short example:
> >
> > <--------------------------->
> > I have an action called editOrder and a form called orderForm.
> > In the reset method of the form:
> >
> > reset(mapping,request) {
> >
> > // check mapping, the form might be used by other actions
> > // that don't want our little featue
> > if (mapping.getType.equals("editOrder") {
> > int orderId = request.getInt("orderId");
> > OrderData order = db.loadOrder(orderId);
> > this.orderName = order.getName();
> > this.orderSize = order.getSize();
> > // .. and so on
> >
> > }
> >
> > }
> > <--------------------------->
> >
> > Any suggestions or thoughts around this way of doing things? Looks nice to
> > me,
> > but I'd sure like to know if there is something nasty that I've missed here.
> >
> > Regards,
> >
> > Mattias Norlander
> >
> >
> > --
> > 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]>
>
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>