You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Giovanni Azua <gi...@imc.nl> on 2008/02/29 09:27:22 UTC

OT: BeanUtils 1.7 and 1.8

hi,

Sorry for the of-topic but given that BeanUtils is heavily used in 
Struts, can anyone suggest why this test does not pass neither in 1.7 
nor 1.8? alternative way using BeanUtils? I had to end up implementing 
my own Reflection-based copyProperties ...

    
//------------------------------------------------------------------------
    public void
    testCopyProperties()
    throws Exception
    {
        class SomeBean
        {
            
//----------------------------------------------------------------
            public final double
            getPropertyA()
            {
                return thePropertyA;
            }

            
//----------------------------------------------------------------
            public final void
            setPropertyA(double aPropertyA)
            {
                thePropertyA = aPropertyA;
            }

            
//----------------------------------------------------------------
            public final double
            getPropertyB()
            {
                return thePropertyB;
            }

            
//----------------------------------------------------------------
            public final void
            setPropertyB(double aPropertyB)
            {
                thePropertyB = aPropertyB;
            }

            
//----------------------------------------------------------------
            /** (non-Javadoc)
             * @see java.lang.Object#toString()
             */
            @Override
            public String
            toString()
            {
                return "(" + getPropertyA() + ", " + getPropertyB() + ")";
            }           

            
//----------------------------------------------------------------
            // members
            
//----------------------------------------------------------------
            private double thePropertyA = 0;
            private double thePropertyB = 0;
        }
       
        Object myBean = new SomeBean();
         
        String myExpected = "(1.0, 1.0)";

        Map<String, Object> myMap = new HashMap<String, Object>();
        myMap.put("PropertyA", 1.0);
        myMap.put("PropertyB", 1.0);

        BeanUtilsBean.getInstance().copyProperties(myBean, myMap);
       
        assertEquals("BeanUtilsBean.copyProperties did not work as 
expected",
            myExpected, myBean.toString());       
    }   

TIA,
regards,
Giovanni 

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


Re: OT: BeanUtils 1.7 and 1.8

Posted by Niall Pemberton <ni...@gmail.com>.
You should ask this on the commons user list:
  http://commons.apache.org/beanutils/mail-lists.html

...but the reason is because you have used the wrong names for keys in
your Map - the first character should be lower case (so "properyA" and
"propertyB") - this is the java beans spec

If you change the key names then it works.

Niall

On Fri, Feb 29, 2008 at 8:27 AM, Giovanni Azua <gi...@imc.nl> wrote:
> hi,
>
>  Sorry for the of-topic but given that BeanUtils is heavily used in
>  Struts, can anyone suggest why this test does not pass neither in 1.7
>  nor 1.8? alternative way using BeanUtils? I had to end up implementing
>  my own Reflection-based copyProperties ...
>
>
>  //------------------------------------------------------------------------
>     public void
>     testCopyProperties()
>     throws Exception
>     {
>         class SomeBean
>         {
>
>  //----------------------------------------------------------------
>             public final double
>             getPropertyA()
>             {
>                 return thePropertyA;
>             }
>
>
>  //----------------------------------------------------------------
>             public final void
>             setPropertyA(double aPropertyA)
>             {
>                 thePropertyA = aPropertyA;
>             }
>
>
>  //----------------------------------------------------------------
>             public final double
>             getPropertyB()
>             {
>                 return thePropertyB;
>             }
>
>
>  //----------------------------------------------------------------
>             public final void
>             setPropertyB(double aPropertyB)
>             {
>                 thePropertyB = aPropertyB;
>             }
>
>
>  //----------------------------------------------------------------
>             /** (non-Javadoc)
>              * @see java.lang.Object#toString()
>              */
>             @Override
>             public String
>             toString()
>             {
>                 return "(" + getPropertyA() + ", " + getPropertyB() + ")";
>             }
>
>
>  //----------------------------------------------------------------
>             // members
>
>  //----------------------------------------------------------------
>             private double thePropertyA = 0;
>             private double thePropertyB = 0;
>         }
>
>         Object myBean = new SomeBean();
>
>         String myExpected = "(1.0, 1.0)";
>
>         Map<String, Object> myMap = new HashMap<String, Object>();
>         myMap.put("PropertyA", 1.0);
>         myMap.put("PropertyB", 1.0);
>
>         BeanUtilsBean.getInstance().copyProperties(myBean, myMap);
>
>         assertEquals("BeanUtilsBean.copyProperties did not work as
>  expected",
>             myExpected, myBean.toString());
>     }
>
>  TIA,
>  regards,
>  Giovanni
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>  For additional commands, e-mail: dev-help@struts.apache.org
>
>

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