You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Sasanka <sa...@yahoo.com> on 2008/11/19 09:26:12 UTC

BeanUtils.copyProperties not working. Pls suggest

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


Re: BeanUtils.copyProperties not working. Pls suggest

Posted by Philip Luppens <ph...@gmail.com>.
On Wed, Nov 19, 2008 at 9:26 AM, Sasanka <sa...@yahoo.com> wrote:
>
> 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.
[snip]

Please ask user questions on the Struts user mailing list. The dev
list is for the development of the Struts framework itself.

- Phil

-- 
"We cannot change the cards we are dealt, just how we play the hand."
- Randy Pausch

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