I would use two things:  a Data Transfer Object(DTO) and
BeanUtils.copyProperties().  I would use a DTO because I do not want to pass
a view component like ActionForm directly to a model component like your
baseDAO.
The DTO might look something like this:

public class Author
{
        String lastName;
}

Then I would use BeanUtils.copyProperties() to copy data from the ActionForm
to the DTO.

The signature for insertAuthor would then be:
  public void insertAuthor(Author author) throws DaoException

-------------------------------------------

1)      Using an ActionForm:

Create your ActionForm that you call AuthorForm.

Then in your Action's execute(...), you could do this:

        AuthorForm authorForm = (AuthorForm) form;
        Author author = new Author();
        BeanUtils.copyProperties(author, authorForm);
        try {
                baseDAO.insertAuthor(author);
        } catch(Exception ex) {
                ex.printStackTrace();
        }

In struts-config.xml, you would have:
<form-bean name="authorForm"
        type="org.apache.struts.action.ActionForm">
        <form-property name="lastName"
                type="java.lang.String"/>
</form-bean>

2)      Using a DynaActionForm:

Almost the same thing, but do not create a separate AuthorForm.

        DynaActionForm authorForm = (DynaActionForm) form;
        Author author = new Author();
        BeanUtils.copyProperties(author, authorForm);
        try {
                baseDAO.insertAuthor(author);
        } catch(Exception ex) {
                ex.printStackTrace();
        }

In struts-config.xml, you would have:
<form-bean name="authorForm"
        type="org.apache.struts.action.DynaActionForm">
        <form-property name="lastName"
                type="java.lang.String"/>
</form-bean>




-----Original Message-----
From: Ricky [mailto:[EMAIL PROTECTED]
Sent: Monday, December 08, 2003 1:44 AM
To: Struts Users Mailing List
Subject: about using DynaActionForm in SQL Maps framework with Struts...


hi, there,
        has anybody tried to use SQL Maps framework with struts? i am now using
the struts with SQL Maps framework, all is convenient. i have tried to use
ActionForm instead of create a new javaBean passed to SQL Map parameter.
just like this:

    AuthorForm authorForm = (AuthorForm) form;

    try {
      baseDAO.insertAuthor(authorForm);
    } catch(Exception ex) {
      ex.printStackTrace();
    }

now, i have a query about using DynaActionForm in it...
assume that i am using DynaActionForm and config in struts-config.xml,
What should i do to pass the dynaformBean to SQL Map parameter?
some code like these, but it threw some exception...

    DynaActionForm authorForm = (DynaActionForm) form;
    try {
      baseDAO.insertAuthor(authorForm);
    } catch(Exception ex) {
      ex.printStackTrace();
    }

and in my BaseDAO.java :

  public void insertAuthor(DynaActionForm author) throws DaoException {
    try {
      javaDIYDaoManager.startTransaction();

      authorDao.insertAuthor(author);

      javaDIYDaoManager.commitTransaction();
    }
    catch (DaoException e) {
      try {
        javaDIYDaoManager.rollbackTransaction();
      }
      catch (Exception e2) { /* ignore */}
      throw ( (DaoException) e.fillInStackTrace());
    }
  }

it threw some exception:

Error executing 'insertAuthor' in 'com/dao/sql/Author.xml'.

Check the Parameter Map (or inline parameters).  Check the 'author_name'
property.

Cause: com.ibatis.common.beans.BeansException: There is no READABLE property
named

'author_name' in class 'org.apache.struts.action.DynaActionForm'

com.ibatis.common.beans.BeansException: There is no READABLE property named
'author_name'

in class 'org.apache.struts.action.DynaActionForm'







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to