aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Prepopulating a DynaActionForm" Watch "Prepopulating a DynaActionForm" New topic
Author

Prepopulating a DynaActionForm

Jarrod Mennuobe
Greenhorn

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"))


Merrill
Consultant, Sima Solutions
Jarrod Mennuobe
Greenhorn

Joined: Oct 05, 2005
Posts: 20
Thanks for the reply. I'll try that.
 
wood burning stoves
 
subject: Prepopulating a DynaActionForm