You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jonathan M Crater <jo...@fanniemae.com> on 2001/09/28 01:55:41 UTC
BeanUtils.populate() not transferring values to bean
when i run the following test class with the org.apache.commons.beanutils.BeanUtils
class the output is null across the board. when i run the same test with
org.apache.struts.util.BeanUtils all the values are transferred from the Map.
anybody have a similar issue? anybody have an explanation?
import org.apache.commons.beanutils.BeanUtils;
import java.util.*;
import java.sql.*;
import java.text.*;
public class Populate {
public static void main(String[] a) {
try {
String trackingId = "sometrackingid";
Timestamp submitDate = new Timestamp(System.currentTimeMillis());
String fileName = "filename";
Timestamp lastUpdated = new Timestamp(System.currentTimeMillis());
int status = 24;
String contactId = "contact";
int initialRequestCount = 4;
int suspendedRequestCount = 6;
int pendingRequestCount = 5;
int processedRequestCount = 7;
int deletedRequestCount = 10;
SubmissionValueObject svo = new SubmissionValueObject();
Map m = new HashMap();
m.put("trackingId", trackingId);
m.put("submitDate", getFormattedTimestamp(submitDate));
m.put("fileName", fileName);
m.put("lastUpdated", getFormattedTimestamp(lastUpdated));
m.put("status", status + "");
m.put("contactId", contactId);
m.put("initialRequestCount", initialRequestCount + "");
m.put("suspendedRequestCount", suspendedRequestCount + "");
m.put("pendingRequestCount", pendingRequestCount + "");
m.put("processedRequestCount", processedRequestCount + "");
m.put("deletedRequestCount", deletedRequestCount + "");
BeanUtils.populate(svo, m);
print("trackingId= " + svo.getTrackingId());
print("submitDate= " + svo.getSubmitDate());
print("fileName= " + svo.getFileName());
print("lastUpdated= " + svo.getLastUpdated());
print("status= " + svo.getStatus());
print("contactId= " + svo.getContactId());
print("initialRequestCount= " + svo.getInitialRequestCount());
print("suspendedRequestCount= " + svo.getSuspendedRequestCount());
print("pendingRequestCount= " + svo.getPendingRequestCount());
print("processedRequestCount= " + svo.getProcessedRequestCount());
print("deletedRequestCount= " + svo.getDeletedRequestCount());
}
catch(Exception e) {
e.printStackTrace();
}
}
public static final String getFormattedTimestamp(Timestamp t) {
if(t == null)
return null;
java.util.Date d = (java.util.Date)t;
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm");
return sdf.format(d);
}
static void print(String s) {
System.out.println(s);
}
}