File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Prepopulating a DynaActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Prepopulating a DynaActionForm" Watch "Prepopulating a DynaActionForm" New topic

Prepopulating a DynaActionForm

Jarrod Mennuobe

Joined: Oct 05, 2005
Posts: 20
I have a web app where users are allowed to edit data stored in a DB. In many cases, they arrive at a page with a form appearing there already filled out with values from the DB.

In the past I always used ordinary ActionForms for this type of situation. Set the fields in an Action and then use the Struts html tags to implement the form, so the values would show up there.

However, for the current project, we're looking at using DynaActionForms. I have searched these forums and done a Google search, but strangely, I can't find any info on how to prepopulate the fields of a DynaActionForm. Is it not normal to do that?

Any help to get in the right direction would be greatly appreciated.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can certainly prepopulate a DynaActionForm. There are a couple of conditions, though. One is that you can't instantiate a DynaActionForm with new DynaActionForm(). You have to associate the action that prepopulates the form with the form bean in the Action mapping. Then, when the Action's execute() method is called, struts instantiates the DynaActionForm and passes it in as a parameter. Since the parameter comes in as type "ActionForm", you have to cast it to "DynaActionForm" so that you can use it.

Once you had the instance, you can call the set() method to populate any variables. (Example: myDynaActionForm.set("lastName", "Smith"))

Consultant, Sima Solutions
Jarrod Mennuobe

Joined: Oct 05, 2005
Posts: 20
Thanks for the reply. I'll try that.
I agree. Here's the link:
subject: Prepopulating a DynaActionForm
It's not a secret anymore!