Vaadin flow 23 how where to add event before logout - spring-data-jpa

I'm using Vaadin flow 23
when the user click logout: my App should be able to stop the chronometere and save time elapsed in my corresponding DB.
who to do it????
I have a SecurityService Class
public void logout() {
UI.getCurrent().getPage().setLocation(LOGOUT_SUCCESS_URL);
SecurityContextLogoutHandler logoutHandler = new SecurityContextLogoutHandler();
logoutHandler.logout( VaadinServletRequest.getCurrent().getHttpServletRequest(),null,null);
}

Related

Events provider is deprecating. Using Redux or Observables for state in ionic apps

I've been using events in my ionic application, where i subscribe in one page, and publish the event in the other page. Now I see a warning that Events are going to be changed with Observables and Redux state and effect.
I was using Events mainly to call for component function changes outside it, so I had a components for example:
Component1.ts
this.events.subscribe('event:addValue1', (data: any) => {
this.valueName = 'VALUE1';
});
this.events.subscribe('event:addValue2', (data: any) => {
this.valueName = 'VALUE2';
});
and than outside this component I was calling the publish methods from any page, like:
Page1.ts
this.events.publish('event:addValue1');
Page2.ts
this.events.publish('event:addValue2');
By this i was able to change the data (this.valueName) outside the Component1.ts from any other page, simply by publishing the desired event.
I know that this might not sound or be right approach, but It was the only way I was doing changes to my Component1.ts outside it from any page.
I have now changed this and just put separate functions and than i access them via ViewChild component name like
#ViewChild('component') component: any;
....
this.component.functionAddValue1().
and additionally I send additional params via Angular NavigationExtras if i need to calculate and call some function from the Component1.ts, lets say if I navigate to some route.
Before this I was just calling the events.publish and I was able to make the changes to the Component1.ts on the fly.
Create event service.
In the EventService.ts:
export class EventService {
private dataObserved = new BehaviorSubject<any>('');
currentEvent = this.dataObserved.asObservable();
constructo(){}
publish(param):void {
this.dataObserved.next(param);
}
}
For publishing the event from example page1:
constructor(public eventService:EventService){}
updatePost(value){
this.eventService.publish({name:'post:updated',params:value});
}
In page 2:
constructor(public eventService:EventService){
eventService.currentEvent.subscribe(value=>{
if(value.name=='post:updated'){
//get value.name
}else if(value.name=='another:event'){
//get value or update view or trigger function or method...
}
// here you can get the value or do whatever you want
});
}

how i can go on particular activity after clicking on notification

i want my application should give me notification and on clicking on notification another activity should open like whatsapp notifications
this is my code c an anyone help?????
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// sendNotification(remoteMessage.getNotification().getBody());
//Bundle bundle=new Bundle();
//bundle.putString("msgBody",remoteMessage.getNotification().getBody());
//intent use for start this activity after click on notification
Intent intent = new Intent(getApplicationContext(),Secondactivity.class);
String valu=remoteMessage.getNotification().getBody();
intent.putExtra("notificationmessage",valu);
**strong text** //here we are telling system after clicking you have to come on mainactivity
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//here we are giving rights to main activity.FLAG_ONE_SHOT useful to indicate this pending intent can use only once
PendingIntent pendingintent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
//notificationcompat useful for creating notification layout
NotificationCompat.Builder notificationbuilder=new NotificationCompat.Builder(this);
notificationbuilder.setContentText(remoteMessage.getNotification().getBody());
notificationbuilder.setContentTitle("FCM NOTIFICATION");
notificationbuilder.setSmallIcon(R.mipmap.ic_launcher);
notificationbuilder.setAutoCancel(true);
notificationbuilder.setContentIntent(pendingintent);
NotificationManager notificationManager= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationbuilder.build());
}
You have to add an extra parameter in the message content for identifying the type. Then create notification manager with different activity based on that type value.
ex:
switch (type){
case 1:
notification manager for activity A
break:
case 2:
notification manager for activity B
break:
}

Timer Based Application In GWTP

I want to create a GWT application. That whenever the user gets logged in to system, it will show some information in PopUpPanel and after some time it gets disabled automatically.Is it possible with GWT ?
Could try something like:
Timer t = new Timer() {
#Override
public void run() {
popUpPanel.hide();
}
};
popUpPanel.show();
t.schedule(5000);
Where 5000 is how long you want to show the pop up for.

What is need History.fireCurrentHistoryState() in GWT History?

Hello I am working on a GWT sample history management application.
Here is my onModuleLoad Code.
public void onModuleLoad() {
ContentPanel panel = ContentPanel.getInstance();
if(History.getToken()!=null && History.getToken().length()==0)
{
History.newItem("first_page");
}
History.addValueChangeHandler(new HistoryHandler());
RootPanel.get().add(panel);
History.fireCurrentHistoryState();
}
In this I fired History.fireCurrentHistoryState(); to fire current state of history.
Now In my firstPanel class ther is button named Second Panel on which history token second_page is fired.
public FirstPanel() {
VerticalPanel panel = new VerticalPanel();
Button button2 = new Button("Second Panel");
button2.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
History.newItem("second_page");
}
});
panel.add(button2);
initWidget(panel);
}
But here no need to fire History.fireCurrentHistoryState() ; again.
simply histtory.newItem works fine.
Now I want to know that what the need of History.fireCurrentHistoryState() at module load time only?
Also why it is not required second time in the application.?
History.fireCurrentHistoryState() invokes your history handlers without actually inserting new history item in browser history stack, while History.newItem(token) does insert new history token into history stack.
Note: if your current token is the same as new token (i.e. same page is reloaded), then browsers do not insert this into history stack. In this case (current token == new token) History.fireCurrentHistoryState() has the same effect as History.newItem(currentToken).

Detecting refresh event in GWT

We need to detect the Refresh event (f5) / reload of the web application.
Is there an event in GWT that can detect this?
thanks,
mj
Add a Window Closing Handler:
HandlerRegistration registration = Window.addClosingHandler(new ClosingHandler() {
void onWindowClosing(ClosingEvent event) {
// call the server, or whatever
}
});
EDIT
The HandlerRegistration is used to deregister the Handler if you don't need it anymore.