struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nuwan Chandrasoma <mymail...@gmail.com>
Subject Re: BeanUtils.copyProperties not working. Pls suggest
Date Wed, 19 Nov 2008 11:48:44 GMT
Hi,

DynaValidatorForm use a Map to keep its value to my understanding. I am not sure BeanUtils.copyProperties
would work on this secnario. i may be wrong :)

Thanks,

Nuwan C.



Sasanka 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.
>
> 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 
>   


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


Mime
View raw message