You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ricky <Ri...@hotmail.com> on 2003/12/08 07:44:27 UTC
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: about using DynaActionForm in SQL Maps framework with
Struts...
Posted by Richard Yee <ry...@cruzio.com>.
Ricky,
You might have a problem using ibatis SQL Maps with Struts DynaForms. I
think that Ibatis is going to try and look for a method called
getAuthor_name() when it would need to use
DynaForm.get("author_name"). You might try emailing
clinton.begin@ibatis.com to get a definitive answer.
-Richard
At 10:44 PM 12/7/2003, you wrote:
>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: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
about using DynaActionForm in SQL Maps framework with Struts...
Posted by Paul McCartney <pm...@gtalumni.org>.
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:Ricky_Yahoo@hotmail.com]
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org