Reputation: 225
I'm using vaadin framework to build my project and i'd like to display a notification when comes a specific date, i have a function that return this date and i'm wondering how to display a message when the system's date reaches this calcalculated date.
//I'd like to display a notification when the system's date reaches this "date_main_levee"
public Date getMainLevee(Date date_ouverture_plis, int duree_caution){
Date date_main_levee;
Calendar c = Calendar.getInstance();
c.setTime(date_ouverture_plis);
c.add(Calendar.DATE, duree_caution);
date_main_levee=c.getTime();
return date_main_levee;
}
Basically what i'm looking for is a solution like this simple one in Android : http://blog.blundell-apps.com/notification-for-a-user-chosen-time/
Is there any proposition for this in vaadin (a java solution will also helps as vaadin is a java Framework).
Edit
my problem is not the notification itself but the service that runs and tests if the actual date is equivalent to a date parameter i gave
Edit 2:
I use this code and it's showing the result in the console but no notification in the UI :
This is the view where i have a simple button, when i click on it the task should start :
final Button annulerLC=new Button("Annuler");
annulerLC.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// TODO Auto-generated method stub
DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = dateFormatter.parse("2015-04-23 18:29:00");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Timer timer = new Timer();
timer.schedule(new CautionTask(), date);
}
});
The TimerTask is defined in this separate class (it just show a notification) :
public class CautionTask extends TimerTask{
public void run()
{
Notification.show("success");//Doesn't show anything
System.out.println("success+++");//Works fine
}
}
I got : success+++ on the Console so system.out.println show the exact result, however the View doesn't display the notification "success".
Thanks.
Upvotes: 2
Views: 1313
Reputation: 4754
When you need "realtime" notifications, then start a background thread in your application init() method, which then displays the notification as needed. Of course you then have to use some push system, so the notifications are pushed to the client. Please also read the section about accessing the UI from another thread.
When you don't need realtime notification, just add the check code to some of your UI forms and then display it there. There is no need for a background service in this case.
You need:
a) Server push so the changes in the background server thread are pushed to the client.
b) Correct access to the UI from a background thread/task, since this runs potentially in another context
Upvotes: 2