This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 28, 2012, 10:22 PM
13 Posts

Java bean and DateTime

  • Category: Managed Beans in NSF
  • Platform: Linux
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 4
 Just starting to look into beans, and I could not find the correct datatype for date/time fields. The problem arises when connecting the date to a date picker.
 
Johnny 
Mar 29, 2012, 1:32 AM
63 Posts
Re: Java bean and DateTime
Hello Johnny!
 
I have not yet used the datetime picker but I did have issues with dates to the back-end.  This probably will not help you, as I did get the date over as a String. 
 
(1) From my JavaBean 

private String Date_Format = "MM/dd/yyyy";

SimpleDateFormat simpledateformat = new SimpleDateFormat(Date_Format);

Calendar calendar = Calendar.getInstance();

private String ExpireDate = simpledateformat.format(calendar.getTime());

  • add getters and setters for ExpireDate
  • then get it in the back-end as such doc.appendItemValue("expireDate", ExpireDate);
     

(2) call it from your Xpage as such
 

<xp:inputText value="#{SendBulletinBean.expireDate}" id="inputText1" style="font-size:9pt" />

 
(3) in the field's properties, reflect the field as String and Not date.
 
Again, you may need the dateTime picker, perhaps this can spring some ideas.
 
L8ter!
Mar 29, 2012, 9:00 AM
261 Posts
Re: Java bean and DateTime
Johnny,
 
I haven't tested this with a bean but if you add the date/time picker to an XPage/ Custom control, a convertDateTime converter is added to the input control. You can probably bind the value to a bean property with a java.util.Date type.
 
To store a java.util.Date in a date/time field of a Notes document you'll need to convert it to a DateTime object. You can do that using the createDateTime method of the Session object:
 
doc.replaceItemValue("yourDateField", session.createDateTime( <your java.util.Date object> ) );
 
Mark
Mar 29, 2012, 12:11 PM
13 Posts
Re: Java bean and DateTime
 Thank you Mark - got it working!
 
This getter will allways set the initial date to "today". 
 
 Bean variable declaration:
  private Date Dato;
 
Getter and setter:
public Date getDato() {
try {
if (Dato == null) {
Dato = new Date();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Dato;
}

public void setDato(Date dato) {
Dato = dato;
}
 
Relevant part of the save method: 
public void save() {
try {
DateTime tmpDato = (DateTime)session.createDateTime(Dato);
docAktivitet.replaceItemValue("DatoDT", tmpDato);
docAktivitet.save();
} catch (NotesException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
 
 And relevant part of the load method:
  public void load(String unid) {
try {
if (docAktivitet != null) {
setDato(docAktivitet.getFirstItem("DatoDT").getDateTimeValue().toJavaDate()); // Date
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Sep 3, 2013, 11:16 PM
1 Posts
worked for me too Thank You!!!

Its never too late :)

This worked for me too.  I just wanted to add.  On the control in the UI, you want to bind the value property through expression language, I did mine like this value = #{transferBean.requestedDate}.  Server side similar to what the other guys posted.


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal