Solved

struts ActionForm vs DynaActionForm

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse buid path vs tomcat lib path 10 46
CSV file parsing thru Java 13 52
Problem to Alipay 10 94
Setup Eclipse for Andriod development 2 18
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

739 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