javabean passing values

How do you pass values from one javabean(where i store some user input with get and set methods from a form), to a second javabean where i want to use them?
[163 byte] By [Reniera] at [2007-10-2 13:47:35]
# 1

There are two ways you can do this.

The first way can be a bit clumsy if there are lots of values to be retrieved and set. You would use the get methods of the first bean to retrieve the values and then invoke the set methods of the second bean with these retrieved values.

The second way is to put another method into the first bean (the one that holds the values). This new method would take the second bean as a parameter and then invoke its set methods with the data it is storing. When you need the second bean set, you would invoke this new method on the first bean passing it the instance of the second bean that you want it to set up.

Gita_Weinera at 2007-7-13 11:45:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If you are feeling lazy, and aren't against using reflection, then the jakarta commons [url http://jakarta.apache.org/commons/beanutils/]BeanUtils package[/url] could be of use.

There is a method BeanUtils.copyProperties(toBean, fromBean)

which goes through copying properties from the "fromBean" to the "toBean" - via the declared get/set methods.

evnafetsa at 2007-7-13 11:45:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...