Bonsoir,
voilà j'ai créer un AsyncCallBack (MyAsyncCallback):
qui implémente AsyncCallback et qui utilise un AjaxHandler:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package fr.unice.xmlteam.client; import com.google.gwt.user.client.rpc.AsyncCallback; public class MyAsyncCallback<T> implements AsyncCallback<T> { private final AjaxHandler handler; private final AsyncCallback<T> delegate; public MyAsyncCallback(AjaxHandler handler, AsyncCallback<T> asyncCallBack) { this.handler = handler; this.delegate = asyncCallBack; handler.onStart(); } public void onFailure(Throwable caught) { handler.onComplete(); handler.onError(); this.delegate.onFailure(caught); } public void onSuccess(T result) { handler.onComplete(); handler.onSuccess(); this.delegate.onSuccess(result); } }
cet MyAjaxHandler hérite de AjaxHandler(Une interface):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package fr.unice.xmlteam.client; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.LayoutPanel; import com.google.gwt.user.client.ui.RootPanel; public class MyAjaxHandler implements AjaxHandler { private Label busyLabel = new Label("Loading..."); private Label errorLabel = new Label("Error"); private LayoutPanel container = new LayoutPanel(); private static MyAjaxHandler instance; private MyAjaxHandler() { } public void onComplete() { container.clear(); RootPanel.get().remove(container); } public static MyAjaxHandler getInstance() { if(instance == null) instance = new MyAjaxHandler(); return instance; } public void onError() { container.add(errorLabel); } public void onStart() { container.clear(); container.add(busyLabel); RootPanel.get().add(container); } public void onSuccess() { onComplete(); } }
Je voudrai utiliser cela pour afficher quelque chose comme "Chargement en cours" par exemple mais je ne sais pas du tout comment l'utiliser.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 package fr.unice.xmlteam.client; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.LayoutPanel; import com.google.gwt.user.client.ui.RootPanel; public class MyAjaxHandler implements AjaxHandler { private Label busyLabel = new Label("Loading..."); private Label errorLabel = new Label("Error"); private LayoutPanel container = new LayoutPanel(); private static MyAjaxHandler instance; private MyAjaxHandler() { } public void onComplete() { container.clear(); RootPanel.get().remove(container); } public static MyAjaxHandler getInstance() { if(instance == null) instance = new MyAjaxHandler(); return instance; } public void onError() { container.add(errorLabel); } public void onStart() { container.clear(); container.add(busyLabel); RootPanel.get().add(container); } public void onSuccess() { onComplete(); } }
*Merci*
Partager