• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prepopulating a DynaActionForm

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"))
 
Jarrod Mennuobe
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I'll try that.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic