Populate a Bean
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Thursday, December 30, 2004 01:02 AM

I am searching a class that fills one bean (dest) with the values of a second bean (source)

Source bean has string properties;

Dest bean has int, string, Date ...

So for example I have to convert String to int or String to Data ...


public class sourceBean() {
public String myVar = "aaa";
public String myVar2 = "bbb";
:
};



public class destBean() {
public int myVar;
public Date myVar2;
:
};


Thanks for hints where to search.

Re: Populate a Bean

Posted By:   Anonymous  
Posted On:   Thursday, December 30, 2004 04:05 AM

I doubt whether you would find a readymade class for your utilization. You could probably write your own. Here's one basic example... you might want to refine it with better error trapping.


public class DataCopier {
public boolean copyData(sourceBean source, destBean dest) {
try {
dest.myVar = Integer.parseInt(source.myVar);
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy"); // I am assuming the format in source to be MM/dd/yyyy
dest.myVar2 = dateFormatter.parse(source.myVar2);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
}

Thanks!
About | Sitemap | Contact