• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 150
  • Last Modified:

BeanUtils

hello  experts,

I want to know what is BeanUtils. In my application, i have an Action form bean which collects the data entered by users.
This data from the Action Form bean should be transfered to Value Objects, and value objects should display the data.
Can we acchieve this using BeanUtils?


thanks in advance,
J

0
jaggernat
Asked:
jaggernat
  • 5
  • 2
1 Solution
 
jaggernatAuthor Commented:
can you give an example?

thanks for the reponse,
J
0
 
aozarovCommented:
public class MyBean
{
private String name;
    MyBean(String name)
{
this.name = name;
}

public String getName()
{
return name;
}

public void setName(String name)
{
this.name = name;
}
}

MyBean bean1 = new MyBean();
bean1.setName("this_is_my_name");
MyBean bean2 = new MyBean();
BeanUtils.copyProperties(bean1, bean2);
System.out.println(bean2.getName());; // This should print "this_is_my_name"

Is this what you were looking for?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aozarovCommented:
Forgot to add empty constructor:
Add this to MyBean

public MyBean()
{
// empty constructor
}
0
 
jaggernatAuthor Commented:
what i am looking for:

i have a frontend html form in Struts. When the frontend form(with values) is submitted, the ActionForm is filled with the values which the user filled in the front end form. This informaiton in the Action Form is passed to the value objects and the value objects calls  session beans.

We are using value objects to decouple the Presentation Layer(containing the action form) and the Business Layer (containing session bean).

So for the time being, i want to take the information from the action form bean and pass it to vaue objects and display the values in WSAD console. then my second step would be to invoke the session bean using value objects.

 Do you think the program you gave above would solve my purpose.
I am new to this, so not really sure.

thanks for the prompt response,
J

0
 
aozarovCommented:
It will not solve your problem but if you take/copy the concept then it will work as you expect (we actually did the same thing).
If Both ActionForm and you DAO object are beans (have getXXX() setXXX() for its properties [replace XXX with the name of the property]),
which I think they are then calling BeanUtils.copyProperties(your_action_form_variable, your_dao_variable); will do the job you are expecting
and copy the values from the action form to the DAO object.
0
 
aozarovCommented:
Did you try it?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now