Hi Abel, Looks like you are just missing some client code to invoke the RPC call and use the returned Library object to populate some widgets in your UI. I would read the documentation here:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideRemoteProcedureCalls There are several ways to do it actually, but the way Google describe it is this (so you might as well start there) public class Foo implements EntryPoint { private LibraryServiceAsync libraryService; public void onModuleLoad() { LibraryServiceAsync libraryService = (LibraryServiceAsync)GWT.create(LibraryService.class); ServiceDefTarget endpoint = (ServiceDefTarget) libraryService; // NB: the "LibraryService" string is what you would put in your foo.gwt.xml file // or your web.xml for deployed web mode running String moduleRelativeURL = GWT.getModuleBaseURL() + "LibraryService"; endpoint.setServiceEntryPoint(moduleRelativeURL); } private void callLibraryService() { libraryService.getAuthor(new AsyncCallback<Library>() { on failure(Throwable t) { Window.alert(t.getMessage()); } onSuccess(Library library) { //use the library object to populate widgets from here } } } Another way to do it that is popular (especially with me since my IDE builds it for me automatically!) is to use a static instance of a utility class to do all the messing around inside the service interface. This significantly de-clutters you code. Here is an example: public interface GenericListService extends RemoteService { List<GenericDTO> getList(int formID); /** * Utility/Convinience class. * Use GenericListService.App.getInstance() to access static instance of GenericListServiceAsync */ public static class App { private static GenericListServiceAsync ourInstance = null; public static synchronized GenericListServiceAsync getInstance() { if (ourInstance == null) { ourInstance = (GenericListServiceAsync) GWT.create(GenericListService.class); ((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "GenericListService"); } return ourInstance; } } } which you can then use more simply in your main code. e.g. private Button startBtn = new Button("Start", new ClickListener() { public void onClick(Widget sender) { GenericListServiceAsync proxy = GenericListService.App.getInstance(); proxy.getList(21, new AsyncCallback() { public void onFailure(Throwable caught) { Window.alert("RPC call failed"); } public void onSuccess(Object result) { List<GenericDTO> data = (ArrayList<GenericDTO>) result; makeForm(data); } }); } }); regards gregor On Sep 1, 8:53 am, Abel B <[EMAIL PROTECTED]> wrote: > Hey, > > Here is some of the code that I had written for the application based > on a mysql test database with one table that has three fields (id, > firstname, lastname). The name of the project is library application. > > for the server side, this is the code that I wrote for > LibraryServiceImpl > > /* > * LibraryServiceImpl.java > * > * Created on 30 August 2008, 15:51 > * > * To change this template, choose Tools | Template Manager > * and open the template in the editor. > */ > > package org.silica.library.test.server; > > import com.google.gwt.user.server.rpc.RemoteServiceServlet; > import java.sql.Connection; > import java.sql.PreparedStatement; > import java.sql.ResultSet; > import java.sql.SQLException; > import javax.naming.InitialContext; > import javax.naming.NamingException; > import javax.sql.DataSource; > import org.silica.library.test.client.Library; > import org.silica.library.test.client.LibraryService; > import com.google.gwt.user.client.rpc.InvocationException; > /** > * > * @author Administrator > */ > > public class LibraryServiceImpl extends RemoteServiceServlet > implements LibraryService { > private static final String QUERY = "select * from authors > where id=2"; > > public Library getAuthor() { > DataSource ds = getDataSource(); > Library author = null; > try { > Connection conn = ds.getConnection(); > PreparedStatement ps = conn.prepareStatement(QUERY); > ResultSet results = ps.executeQuery(); > while (results.next()) { > author = new Library(); > > author.setId(results.getInt("id")); > author.setFname(results.getString("firstname")); > author.setLname(results.getString("lastname")); > } > conn.close(); > return author; > } catch (SQLException e){ > throw new InvocationException("Exeption querying database",e); > } > } > > private static DataSource getDataSource(){ > InitialContext ctx; > try { > ctx = new InitialContext(); > return > (DataSource)ctx.lookup("java:comp/env/jdbc/MyDataSource"); > } catch (NamingException e) { > throw new InvocationException("Exception getting > datasoure",e); > } > } > > } > > The following is my client side code > > 1) > /* > * Library.java > */ > package org.silica.library.test.client; > > import com.google.gwt.user.client.rpc.IsSerializable; > > public class Library implements IsSerializable { > private int id; > private String fname; > private String lname; > > public void setId(int id) { > this.id = id; > } > > public int getId() { > return id; > } > > public void setFname(String fname) { > this.fname = fname; > } > > public String getFname() { > return lname; > } > > public void setLname(String lname) { > this.lname = lname; > } > > public String getLname() { > return lname; > } > > } > > 2) > > /* > * LibraryService.java > * > * Created on 30 August 2008, 15:51 > * > * To change this template, choose Tools | Template Manager > * and open the template in the editor. > */ > > package org.silica.library.test.client; > > import com.google.gwt.user.client.rpc.RemoteService; > > public interface LibraryService extends RemoteService{ > public Library getAuthor(); > > } > > 3) > /* > * LibraryServiceAsync.java > * > */ > > package org.silica.library.test.client; > > import com.google.gwt.user.client.rpc.AsyncCallback; > > public interface LibraryServiceAsync { > public void getAuthor(AsyncCallback callback); > > } > > Based on this code how can I be able to display the id, firstname and > lastname fields of the db simply to atleast show that I can get stuff > from a db and render it? > > On Sep 1, 2:18 am, "Jim Freeze" <[EMAIL PROTECTED]> wrote: > > > On Sun, Aug 31, 2008 at 3:43 AM, Abel B <[EMAIL PROTECTED]> wrote: > > > > Hi, I am new to both the java language and gwt. I have been reading on > > > the language for a few months and I have a grasp on some of the most > > > important concepts. > > > > I have been having a hard time rendering data on a browser aftre > > > making server side calls to a mysql db. I have read about using remote > > > procedure calls on the server side and then using the entry point > > > class to render the info retrieved from the application service. > > > > Is there anyone who knows where I can get a step by step guide on > > > working with CRUD functions and rendering them on the browser using > > > gwt. I'm at a loss on what im doing wrong. > > > I use RequestBuilder and format the response data with json. > > It's actually very straightforward. > > > Where exactly are you having problems? > > Can you show us some code that isn't working? > > > -- > > Jim Freeze --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
