Vaadin datefield component set a default date - java

My question is if I put a date field in my web application's UI using vaadin framework like following codes, then how can I set a default date value to it? I can also see the setValue() method suggestion coming with date field in eclipse editor but has not much information how to set a particular date with setValue() in its documentation.
DateField dueDate = new DateField();
dueDate.setDateFormat("dd-MM-yyyy");
dueDate.setVisible(true);
dueDate.setCaption("Due Date");
**dueDate.setValue();**
Thanks in advance for your concerns. I am using vaadin7.

It's indeed the setValue method you need to call. You can supply a java.util.Date object. The first code example on this documentation page shows it.
// Create a DateField with the default style
DateField date = new DateField();
// Set the date and time to present
date.setValue(new Date());
If you are on Java 8 and want to use a LocalDate or LocalDateTime, you need to convert it to java.util.Date or write a Converter for the DateField (I did that some time ago, see here).

Related

JIRA : default date class override

We are trying to change JIRA default display dates to shamsi/jalali Date (Persian date).
Is it possible to write a plugin to override the default date format display of JIRA? How?

Lotus Notes : Insert date value in Lotus Notes form using java agent

I am trying to upload the data from a delimited text file to the lotus notes form using java agent. The issue arises when I try to insert the date value to the notes document. After insert when i use ComputeWithForm, then it returns false. I am using simpledateformat to format the date in MM/dd/yyyy format, but it is still not working. Below is the excerpt from my code.
String delim, key, thekey, myDate;
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy);
myDate = dateFormat.format(date);
newdoc.replaceItemValue("UploadDBDate", myDate);
Any help will be great.
Thanks,
Himanshu
myDate is a String object. The replaceItemValue method does not know that you have put a date into that String, therefore it treats it as ordinary text. If uploadDBDate is a DateTime field, that causes a type mismatch during the computeWithForm operation.
The Lotus classes for Java include a DateTime class. The Session class has a createDateTime method that you pass a "mm/dd/yyyy" string and return a DateTime object. Then you can pass that DateTime object into replaceItemValue instead of passing in myDate.
I would recommend you to do those things:
1) disable computewithform and simply save document and then verify field UploadDBDate, does it have correct value? does it have corrrect type?
2) if everything is fine with UploadDBDate then there is a problem on a form, so try to investigate what calculation you do on the form, because problem is there.

RichFaces 4.2 Calendar. How can I set the InputField of Calendar by JavaScript?

I have to copy a Date String at client side to the Calendar input field "renewal_date_input". The following JavaSript did not work:
document.getElementById('AddressDetails:renewal_date_input').value = renewalDateCombo.value.toString();
Although with:
alert("written date is: " + document.getElementById('AddressDetails:renewal_date_input').value);
We can read out the correct date string written previously.
But the string does not appear in the input field.
Manual Input is enabled:
enableManualInput="true"
Perhaps the JavaScript Function setInputField: function(dateStr, event) shipped with rich faces calendar.js could help, but how do I use it?
Use the setValue() function on the date component, passing a Date object as argument
var theCalendar = document.getElementById('AddressDetails:renewal_date_input');
theCalendar.setValue(document.getElementById('AddressDetails:renewal_date_input').getValue()); //Here I assume renewal_date_input is also a calendar component

RichFaces 4.2 Calendar - How to set the Input Field of Calendar by JavaScript? [duplicate]

I have to copy a Date String at client side to the Calendar input field "renewal_date_input". The following JavaSript did not work:
document.getElementById('AddressDetails:renewal_date_input').value = renewalDateCombo.value.toString();
Although with:
alert("written date is: " + document.getElementById('AddressDetails:renewal_date_input').value);
We can read out the correct date string written previously.
But the string does not appear in the input field.
Manual Input is enabled:
enableManualInput="true"
Perhaps the JavaScript Function setInputField: function(dateStr, event) shipped with rich faces calendar.js could help, but how do I use it?
Use the setValue() function on the date component, passing a Date object as argument
var theCalendar = document.getElementById('AddressDetails:renewal_date_input');
theCalendar.setValue(document.getElementById('AddressDetails:renewal_date_input').getValue()); //Here I assume renewal_date_input is also a calendar component

request.getParameter String value pass as date to java

In my JSP page I have a field which is date and when I getting as request.getParameter("dateVal"); gives me
15-Dec-2012 12:21.
I would like to pass this value to my database procedure and insert/update into table.
How can I pass the value as setDate using prepareCall to database?
Thanks
First step would be using SimpleDateFormat to parse it to a fullworthy java.util.Date instance in the controller:
Date date = new SimpleDateFormat("dd-MMM-yyyy HH:mm.", Locale.ENGLISH).parse(dateVal);
Then you can just create a java.sql.Date around its time in the database layer:
statement.setDate(1, new java.sql.Date(date.getTime()));
Unrelated to the concrete problem, please note that java.sql.Date doesn't remember the time part. If you have actually a DATETIME or TIMESTAMP field in the DB and not a DATE field, then rather use setTimestamp() with a java.sql.Timestamp instead. This way the time part will also be stored.
#BalusC 's answer is perfect. But as an alternative solution you can use the function provided by database to convert String to Date while querying. For example(in case you use Oracle),
to_date(date_in_String, format)
Try this :
new SimpleDateFormat("dd-MM-yyyy HH:mm").parse(mydate);

Categories