Solved

struts ActionForm vs DynaActionForm

Posted on 2011-09-06
2
377 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 50
oracle 11g 23 73
How to convert String matching to regex in java 4 30
Opening PDF on button click and fill new document 2 35
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

816 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

6 Experts available now in Live!

Get 1:1 Help Now