IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GWT et Vaadin Java Discussion :

Comment utiliser MyAsyncCallback?


Sujet :

GWT et Vaadin Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de zemzoum89
    Profil pro
    Étudiant
    Inscrit en
    Janvier 2010
    Messages
    373
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2010
    Messages : 373
    Par défaut Comment utiliser MyAsyncCallback?
    Bonsoir,

    voilà j'ai créer un AsyncCallBack (MyAsyncCallback):
    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);
        }
     
    }
    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
    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();
        }
     
    }
    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.

    *Merci*

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2003
    Messages : 59
    Par défaut
    Comment utilises-tu ce AsyncCallBack ?


    Normalement, tu peux écrire ton message de progression juste avant de faire l'appel à ton service "RPC" et changer ce message dans la méthode "onSuccess" de cet AsyncCallBack.

    Comme c'est un appel asynchrone,
    Ton message va s'afficher et quand le résultat du service arrivera au client, tu pourras afficher un autre message ou effacer le précédent - traiter ton résultat dans la méthode AsyncCallBack.onSucess().

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Mars 2003
    Messages
    59
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2003
    Messages : 59
    Par défaut
    Tu as un exemple:

    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
     
    // This code is called before the RPC starts
     //
      if (startRow == lastStartRow) {
        ...
      }
     
      // Invoke the RPC call, implementing the callback methods inline:
      //
      calService.getPeople(startRow, maxRows, new AsyncCallback<Person[]>() {
     
        // When the RPC returns, this code will be called if the RPC fails
        public void onFailure(Throwable caught) {
           statusLabel.setText("Query failed: " + caught.getMessage());
           acceptor.failed(caught);
        }
     
        // When the RPC returns, this code is called if the RPC succeeds
        public void onSuccess(Person[] result) {
          lastStartRow = startRow;
          lastMaxRows = maxRows;
          lastPeople = result;
          pushResults(acceptor, startRow, result);
          statusLabel.setText("Query reutrned " + result.length + " rows.");
        }
      });
     
      // The above method call will not block, but return immediately.
      // The following code will execute while the RPC is in progress, 
      // before either of onFailure() or onSuccess() are executed.
      //
      statusLabel.setText("Query in progress...");
      ...
    dispo à la page suivante:
    http://code.google.com/webtoolkit/do...eRPCDeployment

Discussions similaires

  1. Réponses: 4
    Dernier message: 24/02/2009, 12h06
  2. Comment utiliser un cache ?
    Par TOM-Z dans le forum XMLRAD
    Réponses: 4
    Dernier message: 14/03/2003, 09h55
  3. comment utiliser actionscript ?
    Par webs dans le forum Flash
    Réponses: 3
    Dernier message: 09/02/2003, 23h11
  4. Comment utiliser OUT ?
    Par Bouziane Abderraouf dans le forum CORBA
    Réponses: 3
    Dernier message: 20/07/2002, 09h35
  5. Réponses: 5
    Dernier message: 11/06/2002, 15h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo