Solved

struts ActionForm vs DynaActionForm

Posted on 2011-09-06
2
361 Views
Last Modified: 2012-05-12
i would like to know about struts ActionForm vs DynaActionForm. when, where, how, why we use each of them, advantages, disadvanges of them. i am not clear on this concept. thanks in advance
0
Comment
Question by:gudii9
2 Comments
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 99 total points
Comment Utility
0
 
LVL 1

Accepted Solution

by:
JavaGuy78 earned 401 total points
Comment Utility
I cast ActionForm to DynaActionForm when the page has multiple rows of similar data, such as a modify page for a lookup list.

for instance, if I have a lookup list on a jsp page, and each item in the lookup list has a Name and a Title, I write something like the code snip. This allows me to pull each row of data out of the page into a series of arrays and then save each row individually.

(if ID is null, the code will insert into the update, else it will update the row in the database.)

ActionForm does not allow you to pull out the data in this manner, so using a DynaActionForm object gives you a bit more functionality for a situation like this.


 
public void saveLookupTable(ActionForm form) {
        DynaActionForm frm = (DynaActionForm) form;
        String[] id     = (String[]) frm.get("id");
        String[] names  = (String[]) frm.get("name");
        String[] titles = (String[]) frm.get("title");

        for (int i = 0; i < id.length; i++) {
            // format each row of data into a useable
            // object and save them to the database.
        }
    }

Open in new window

//in the loop, I write something like this:

LookupBean lb = new LookupBean();
lb.setId(id[i]);
lb.setName(names[i]);
lb.setTitle(titles[i]);
//save bean in database

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now