Update Date value in Database table/VO through a Managed Bean

A lot of time can be spent trying to convert objects to different types to make them compatible to different reference points. I had a problem where I had to update the Date value in a VO through a managed bean and spent a fair amount of time getting the types correct. So here is the code to do so:

//imports for following code
import java.sql.Timestamp;
import java.util.Date;
import oracle.adf.model.AttributeBinding;

//Get current date/time to be used to update VO date value
Date currentDate = new Date();

//Convert date variable to DB Date type
oracle.jbo.domain.Date date = new oracle.jbo.domain.Date(newTimestamp(currentDate.getTime())); 

//Get the attribute that the Date is set to in your page
AttributeBinding dateTimeAttr = AttributeBinding)bindings.getControlBinding("DateTime"); 

//Set the attribute with the newly created date variable
noteCreatedDateAttr.setInputValue(date);

1 comment: