开发者

GWT - Manage a boolean method in the RPC configuration

I have make my own method in the RPC schema by us开发者_运维问答ing the GWT framework. Now, i need to add another method.

So, i wrote this code for each part of RPC :

package org.sinfonet.client;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("gwtservice")
public interface GWTService extends RemoteService {
    public String checkLogin(String nickname, String password);
    public boolean anotherFunction(String nickname);
}

#########################################################

package org.sinfonet.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface GWTServiceAsync {
    public void checkLogin(String nickname, String password, AsyncCallback<String> callback);
    public void anotherFunction(String nickname, AsyncCallback<java.lang.Boolean> asyncCallback);
}    

#########################################################

package org.sinfonet.server;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.ArrayList;

import org.sinfonet.client.GWTService;
import org.sinfonet.mgmt.Configuration;
import org.sinfonet.mgmt.Database;

public class GWTServiceImpl extends RemoteServiceServlet implements GWTService {
    public String checkLogin(String nickname, String password) {
        Database mydb=Configuration.getDatabase();
        mydb.connetti();

        // faccio md5 ed escape
        String log_check_user=nickname;
        String log_check_pass=password;

        // controllo che l'utente esista
        ArrayList<String[]> db_result=null;
        db_result=mydb.selectQuery("SELECT nickname FROM users WHERE nickname='"+log_check_user+"' AND password='"+log_check_pass+"'");
        if(db_result.size()!=0) {
            return "YES";
        }

        // sconnessione al database
        mydb.disconnetti();

        return "NO";
    }

    public boolean anotherFunction(String nickname) {
        // somethings others
        return true;
    }
}

#########################################################

final AsyncCallback<java.lang.Boolean> callCheckLogin = new AsyncCallback<java.lang.Boolean>() {
    public void onSuccess(boolean result) {
        if(result) {
            designLogout(menu_login_label1.getText());
        } else {
            menu_err.setText("Username e password non validi");
        }
    }
};

// Listen for the button clicks
menu_login_button.addClickHandler(new ClickHandler(){
    public void onClick(ClickEvent event) {
        // Make remote call. Control flow will continue immediately and later
        // 'callback' will be invoked when the RPC completes.
        getService().anotherFunction(menu_login_input1.getText(), callCheckLogin);
    }
});

as you can see, i added the anotherFunction() method (boolean), but Netbeans says to me that i need to implements all abracts method about allCheckLogin, but i wont do it :) How can I fix this problem?


So Netbeans complains about the missing onFailure method, right? If you don't want to implement that method every time, write yourself an abstract class like:

public abstract class BaseAsyncCallback<T> implements AsyncCallback<T> {
    @Override
    public void onFailure(Throwable caught) {
        // Perform generic failure handling
    }
}

Then you can change your code into:

final AsyncCallback<java.lang.Boolean> callCheckLogin = 
    new BaseAsyncCallback<java.lang.Boolean>() {
      public void onSuccess(java.lang.Boolean result) {
        ...
      }
    };

Now you don't need to implement onFailure anymore, except if you need to perform additional error handling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜