You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alexander Czernay <al...@czernay.com> on 2004/11/17 12:22:18 UTC

Prepopulate a DynaForm

I'm trying to prepopulate a DynaForm with some values - right now just 
hard-coded, later should be taken from a DB. For that I'm using a 
SetupAction, that is called to prepopulate the form, insert it into the 
request and after that forward to the actual action for presenting the 
form to the user.

Looks like this:

public class MediaArchiveSetupAction extends Action {
      public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response){
         
          ActionServlet servlet = this.getServlet();
          MediaArchiveForm mediaArchiveForm = new MediaArchiveForm();
          mediaArchiveForm.setServlet(this.getServlet());

          MessageResources messageResources = servlet.getInternal();

          mediaArchiveForm.set("author", "test");

         
        // TODO: check why this doesn't work
        request.setAttribute("mediaArchiveForm", mediaArchiveForm);
        // this does actually work
        request.setAttribute("test", "dummy");

          return (mapping.findForward("success"));
      }
}

Using this approach I always get a null pointer exception, leading me to 
the presumption that the actual form-object isn't built.

Any ideas why?

Thanks for any help,
Alexander


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


RE: Prepopulate a DynaForm

Posted by Robert Taylor <rt...@mulework.com>.
You need to use the form which is passed in from the execute()
method signature.  

DynaForm dForm = (DynaForm) form;
dForm.set("author", "test");
return mapping.findForward("success");

This assumes you are using the same form for your setup and processing
action and you are forwarding to the page which renders the form.

robert

> -----Original Message-----
> From: Alexander Czernay [mailto:alexander@czernay.com]
> Sent: Wednesday, November 17, 2004 6:22 AM
> To: Struts Users Mailing List
> Subject: Prepopulate a DynaForm
> 
> 
> I'm trying to prepopulate a DynaForm with some values - right now just 
> hard-coded, later should be taken from a DB. For that I'm using a 
> SetupAction, that is called to prepopulate the form, insert it into the 
> request and after that forward to the actual action for presenting the 
> form to the user.
> 
> Looks like this:
> 
> public class MediaArchiveSetupAction extends Action {
>       public ActionForward execute(ActionMapping mapping,
>             ActionForm form,
>             HttpServletRequest request,
>             HttpServletResponse response){
>          
>           ActionServlet servlet = this.getServlet();
>           MediaArchiveForm mediaArchiveForm = new MediaArchiveForm();
>           mediaArchiveForm.setServlet(this.getServlet());
> 
>           MessageResources messageResources = servlet.getInternal();
> 
>           mediaArchiveForm.set("author", "test");
> 
>          
>         // TODO: check why this doesn't work
>         request.setAttribute("mediaArchiveForm", mediaArchiveForm);
>         // this does actually work
>         request.setAttribute("test", "dummy");
> 
>           return (mapping.findForward("success"));
>       }
> }
> 
> Using this approach I always get a null pointer exception, leading me to 
> the presumption that the actual form-object isn't built.
> 
> Any ideas why?
> 
> Thanks for any help,
> Alexander
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

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