ilovetolearn
ilovetolearn

Reputation: 2060

Understanding ActionForm

I have just started learning struts. Most of the tutorials I read, it mentions capturing data using an ActionForm. ie. Performing a http post request with a form filled with data.

However, upon the initial loading of the form, populating of the dropdown boxes etc. How should I retrieve the data and populate to the view?

  1. By saving the ArrayList to the request attribute and iterate it on the jsp.

  2. Setting the ArrayList to a corresponding string[] array in the ActionForm.

Which is the correct / better implementation approach?

Upvotes: 0

Views: 229

Answers (2)

Dave Newton
Dave Newton

Reputation: 160191

Two options:

  • Use the ActionForm
  • Use scoped attribute(s) (generally request)

I prefer to use the ActionForm only for form input data, but there are just as many people that say it should be used for anything in the form, including drop-down values.

(Some say it should be used for everything on a page, but they're clearly mad.)

Keeping data out of ActionForms reduces framework coupling. This may make a transition to a modern framework that expects data to live in scoped attributes, either free-form or in a model object.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240900

in your Action class you can fetch the data using services and store it in a List which is a property of a Form

Upvotes: 1

Related Questions