More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Getting message from the server using RPC( Remote Procedure Call ) 
 

This examples describes the procedure of retrieving message from the server via RPC.

 

Getting message from the server using RPC( Remote Procedure Call )

                         

This examples describes the procedure of retrieving message from the server via RPC. The steps involved in geting message from the server are described below:-

Step1:-Right-click on the GWT project node which you have created and choose New > Other. In the New File wizard, click on the Google Web Toolkit category shows a file template named GWT RPC Service. Click Next.
Step2:-
Fill the sub package box, the name of the package where the files that will be generated will be stored.
Step3:-Click Finish. The Projects window will automatically updates to reflect changes
Step4:- Create the following Classes.

GWTService.java:- This is the client-side definition of the service.

package org.yournamehere.client;
import com.google.gwt.user.client.rpc.RemoteService;
public interface GWTService extends RemoteService{
    public String myMethod(String s);
}

GWTServiceAsync.java:-This is the client side definition. It provides a callback object that enables the asynchronous communication between server and client.

package org.yournamehere.client;
import com.google.gwt.user.client.rpc.AsyncCallback;

public interface GWTServiceAsync {
    public void myMethod(String s, AsyncCallback callback);
}

GWTServiceImpl.java:-This is the servlet that implements the interface. it provides the functionality for retrieving a quote via RPC.

package org.yournamehere.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.yournamehere.client.GWTService;

public class GWTServiceImpl extends RemoteServiceServlet implements
    GWTService {

    public String myMethod(String s) {
        return "Server says: " + s;
    }
}

GWTServiceUsageExample.java:-This is the interface that will instantiates the service.


package org.yournamehere.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class GWTServiceUsageExample extends VerticalPanel {
    private Label lblServerReply = new Label();
    private TextBox txtUserInput = new TextBox();
    private Button btnSend = new Button("Send to server");
    
    public GWTServiceUsageExample() {
        add(new Label("Input your text: "));
        add(txtUserInput);
        add(btnSend);
        add(lblServerReply);

        final AsyncCallback callback = new AsyncCallback() {
            public void onSuccess(Object result) {
                lblServerReply.setText((String)result);
            }
            
            public void onFailure(Throwable caught) {
                lblServerReply.setText("Communication failed");
            }
        };
        
          btnSend.addClickListener(new ClickListener(){
            public void onClick(Widget w) {
                       getService().myMethod(txtUserInput.getText(), callback);
            }
        });
    }
    
    public static GWTServiceAsync getService(){
       
        GWTServiceAsync service = (GWTServiceAsyncGWT.create(GWTService.class);
        ServiceDefTarget endpoint = (ServiceDefTargetservice;
        String moduleRelativeURL = GWT.getModuleBaseURL() "gwtservice";
        endpoint.setServiceEntryPoint(moduleRelativeURL);
        return service;
    }
}

Step4:-Change the entry point of class MainEntryPoint.java.Modify the onModuleLoad() method of the class to the following :-

public void onModuleLoad() {

        RootPanel.get().add(new GWTServiceUsageExample());
    }

Step6:-In the Projects window, right-click the project node and choose Run.

Output of the program

Download source code

                         

» View all related tutorials
Related Tags: c xml file server data gwt vi using this ie example exam e il des trie from in ml m

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.