• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Prepopulating a DynaActionForm  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Thanks for the reply. I'll try that.
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!