You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sharath <ka...@yahoo.com> on 2009/10/30 17:59:24 UTC

Creating Map with multiple beans using apache BeanUtils.

Hi All,

   Say I'm having following beans

    public class Employee
    {
         private String emp_name;
         private String emp_no;
         private Timestamp emp_doj;

          
         public String getEmp_name() {
	return emp_name;
         }
         public void setEmp_name(String emp_name) {
	this.emp_name = emp_name;
         }
      
         public String getEmp_no() {
	return emp_no;
         }
         public void setEmp_no(String emp_no) {
	this.emp_no = emp_no;
         }



         public Timestamp getEmp_doj() {
		return emp_doj;
	}
	public void setEmp_doj(Timestamp emp_doj) {
		this.emp_doj = emp_doj;
	}
    }//End of Employee

    Similary I have Department Bean

    public class Department
    {
         private String dept_name;
         private String dept_no;

         //getter & setter for these properties
    }

   say in my example program

   public class Example {

     public static void main(String args[])
     {
             Employee emp = new Employee();
             emp.setEmp_name("Robert");
             emp.setEmp_no("10001-A");
             emp.setEmp_doj(java.util.getDate());

             Department dept = new Department();
             dept.setDept_name("Computers");
             dept.setDept_no("101");

             //Now I'd like to prepare Map with all employee properties and
also department properties
              Map empdeptDetails = new HashMap();

 
     }//End of main


   }//End of Example


   How to populate empdeptDetails map with employee and department details,
empdeptDetails  should contains properties of employee and department beans.

    empdeptDetails map will have emp_name,emp_no,emp_doj,dept_name, dept_no
values.

    How can we can do this, whether we can create another DynaBean with
these properties, if possible how to create DynaBean?

    Please advice me.

    Thanks for your help in advance.

Regards,
Sharath.

-- 
View this message in context: http://old.nabble.com/Creating-Map-with-multiple-beans-using-apache-BeanUtils.-tp26133572p26133572.html
Sent from the Commons - Dev mailing list archive at Nabble.com.


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


Re: Creating Map with multiple beans using apache BeanUtils.

Posted by sharath <ka...@yahoo.com>.


sharath wrote:
> 
> Hi All,
> 
>    Say I'm having following beans
> 
>     public class Employee
>     {
>          private String emp_name;
>          private String emp_no;
>          private Timestamp emp_doj;
> 
>           
>          public String getEmp_name() {
> 	return emp_name;
>          }
>          public void setEmp_name(String emp_name) {
> 	this.emp_name = emp_name;
>          }
>       
>          public String getEmp_no() {
> 	return emp_no;
>          }
>          public void setEmp_no(String emp_no) {
> 	this.emp_no = emp_no;
>          }
> 
> 
> 
>          public Timestamp getEmp_doj() {
> 		return emp_doj;
> 	}
> 	public void setEmp_doj(Timestamp emp_doj) {
> 		this.emp_doj = emp_doj;
> 	}
>     }//End of Employee
> 
>     Similary I have Department Bean
> 
>     public class Department
>     {
>          private String dept_name;
>          private String dept_no;
> 
>          //getter & setter for these properties
>     }
> 
>    say in my example program
> 
>    public class Example {
> 
>      public static void main(String args[])
>      {
>              Employee emp = new Employee();
>              emp.setEmp_name("Robert");
>              emp.setEmp_no("10001-A");
>              emp.setEmp_doj(java.util.getDate());
> 
>              Department dept = new Department();
>              dept.setDept_name("Computers");
>              dept.setDept_no("101");
> 
>              //Now I'd like to prepare Map with all employee properties
> and also department properties
>               Map empdeptDetails = new HashMap();
> 
>  
>      }//End of main
> 
> 
>    }//End of Example
> 
> 
>    How to populate empdeptDetails map with employee and department
> details, empdeptDetails  should contains properties of employee and
> department beans.
> 
>     empdeptDetails map will have emp_name,emp_no,emp_doj,dept_name,
> dept_no values.
> 
>     How can we can do this, whether we can create another DynaBean with
> these properties, if possible how to create DynaBean?
> 
>     Please advice me.
> 
>     Thanks for your help in advance.
> 
> Regards,
> Sharath.
> 
> 


Thanks, it worked. I tried this method incorrectly. 
-- 
View this message in context: http://old.nabble.com/Creating-Map-with-multiple-beans-using-apache-BeanUtils.-tp26133572p26136252.html
Sent from the Commons - Dev mailing list archive at Nabble.com.


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


Re: Creating Map with multiple beans using apache BeanUtils.

Posted by James Carman <ja...@carmanconsulting.com>.
empdeptDetails.putAll(BeanUtils.describe(emp));
empdeptDetails.putAll(BeanUtils.describe(dept));

On Fri, Oct 30, 2009 at 12:59 PM, sharath <ka...@yahoo.com> wrote:
>
> Hi All,
>
>   Say I'm having following beans
>
>    public class Employee
>    {
>         private String emp_name;
>         private String emp_no;
>         private Timestamp emp_doj;
>
>
>         public String getEmp_name() {
>        return emp_name;
>         }
>         public void setEmp_name(String emp_name) {
>        this.emp_name = emp_name;
>         }
>
>         public String getEmp_no() {
>        return emp_no;
>         }
>         public void setEmp_no(String emp_no) {
>        this.emp_no = emp_no;
>         }
>
>
>
>         public Timestamp getEmp_doj() {
>                return emp_doj;
>        }
>        public void setEmp_doj(Timestamp emp_doj) {
>                this.emp_doj = emp_doj;
>        }
>    }//End of Employee
>
>    Similary I have Department Bean
>
>    public class Department
>    {
>         private String dept_name;
>         private String dept_no;
>
>         //getter & setter for these properties
>    }
>
>   say in my example program
>
>   public class Example {
>
>     public static void main(String args[])
>     {
>             Employee emp = new Employee();
>             emp.setEmp_name("Robert");
>             emp.setEmp_no("10001-A");
>             emp.setEmp_doj(java.util.getDate());
>
>             Department dept = new Department();
>             dept.setDept_name("Computers");
>             dept.setDept_no("101");
>
>             //Now I'd like to prepare Map with all employee properties and
> also department properties
>              Map empdeptDetails = new HashMap();
>
>
>     }//End of main
>
>
>   }//End of Example
>
>
>   How to populate empdeptDetails map with employee and department details,
> empdeptDetails  should contains properties of employee and department beans.
>
>    empdeptDetails map will have emp_name,emp_no,emp_doj,dept_name, dept_no
> values.
>
>    How can we can do this, whether we can create another DynaBean with
> these properties, if possible how to create DynaBean?
>
>    Please advice me.
>
>    Thanks for your help in advance.
>
> Regards,
> Sharath.
>
> --
> View this message in context: http://old.nabble.com/Creating-Map-with-multiple-beans-using-apache-BeanUtils.-tp26133572p26133572.html
> Sent from the Commons - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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