?
Solved

struts ActionForm vs DynaActionForm

Posted on 2011-09-06
2
Medium Priority
?
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 396 total points
ID: 36493562
0
 
LVL 1

Accepted Solution

by:
JavaGuy78 earned 1604 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 …
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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