struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sasanka <sasanka...@yahoo.com>
Subject BeanUtils.copyProperties not working. Pls suggest
Date Wed, 19 Nov 2008 08:26:12 GMT

Hi, I am trying to use BeanUtils.copyProperties(dest, source) to
automatically populate my model bean from the struts form bean. But it seems
the values are not getting copied. I am able to access the value from
ActioForm in Struts Action but post BeanUtils.copyProperties I am not able
access the values from the Value object.

This is my struts-config (partly) :
 <form-beans>    
                <form-bean      name="CreditCardEntryForm"     
type="org.apache.struts.validator.DynaValidatorForm">
                        <form-property          name="cardtype"          
type="java.lang.String"/> 
                        <form-property          name="nameasoncard"      
type="java.lang.String"/> 
                        <form-property          name="cardno"            
type="java.lang.String"/>                     
                        <form-property          name="expmonth"          
type="java.lang.String"/> 
                        <form-property          name="expyear"           
type="java.lang.String"/> 
                        <form-property          name="suiteno"           
type="java.lang.String"/> 
                        <form-property          name="state"             
type="java.lang.String"/> 
                        <form-property          name="streetadd"         
type="java.lang.String"/> 
                        <form-property          name="zipno"             
type="java.lang.String"/> 
                        <form-property          name="city"                  
type="java.lang.String"/> 
                        <form-property          name="country"           
type="java.lang.String"/> 
                </form-bean>
   </form-beans>
 
This is my Struts Action :
 
.....
.....
import org.apache.commons.beanutils.BeanUtils;
import com.pgwrapper.model.CreditCardVO;
 
public final class CreditCardDataAction extends Action
{
        public ActionForward execute( ActionMapping mapping, 
                                                                  ActionForm
form,
                                                                 
HttpServletRequest request,
                                                                 
HttpServletResponse response
                                                                 )
                                                                 throws
IOException //,  ServletException 
        {
 
                final Category logger =
Category.getInstance(com.pgwrapper.handler.CreditCardDataAction.class);
 
.....
.....
                
                DynaValidatorForm creditCardForm = (DynaValidatorForm) form;
                                                
                CreditCardVO creditCard          = new CreditCardVO(); 
        
                try 
                {
                        BeanUtils.copyProperties(creditCard,
creditCardForm);
                } 
                catch (IllegalAccessException e) 
                {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } 
                catch (InvocationTargetException e) 
                {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } 
 
This is my Value Object (partly) :
 
public class CreditCardVO implements java.io.Serializable
{
 
        final Category logger = Category.getInstance
(com.pgwrapper.model.CreditCardVO.class);           
        private String cardtype;
        private String nameasoncard;
        private String cardno;
        private String expmonth;
        private String expyear;
        private String suiteno;
        private String state;
        private String streetadd;
        private String zipno;
        private String city;
        private String country;
        
        public CreditCardVO() 
        {
        }
 
        public String getCardtype()
        {
                return this.cardtype;
        }
        public void setCardtype(String cardtype)
        {
                this.cardtype = cardtype;
        }
....
....
other setter and getter methods ....


Pls suggest
Thanks Sasanka 
-- 
View this message in context: http://www.nabble.com/BeanUtils.copyProperties-not-working.-Pls-suggest-tp20575471p20575471.html
Sent from the Struts - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message