Solved

struts ActionForm vs DynaActionForm

Posted on 2011-09-06
2
372 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
ID: 36493562
0
 
LVL 1

Accepted Solution

by:
JavaGuy78 earned 401 total points
ID: 36545605
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

896 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

14 Experts available now in Live!

Get 1:1 Help Now