-
6 Jan 2009 4:23 PM #1
Weird Error
Weird Error
Hi,
I have a class called CadaoDb.java in com.cadao.server package. In my entry point class, platform.java, I import com.cadao.CadaoDb. No matter what I try, it repeatedly complains this error:
[ERROR] Errors in 'file:/C:/Documents%20and%20Settings/Administrator/My%20Documents/My%20Data/cd/gxt/platform/src/com/cadao/client/platform.java'
[ERROR] Line 5: The import com.cadao.server.CadaoDb cannot be resolved
Here are the files:
1- Entry Point: platform.java
2- Config file: platform.gwt.xmlCode:package com.cadao.client; import java.sql.Connection; import com.cadao.server.CadaoDb; import com.google.gwt.core.client.EntryPoint; public class platform implements EntryPoint { public void onModuleLoad() { CadaoDb cadaoDb = new CadaoDb(); Connection connection = cadaoDb.getConnection(); System.out.println(connection.toString()); } }
3- Attached is the snapshot of my file hierarchy in zip format (sorry, it's too big).Code:<module> <inherits name='com.google.gwt.user.User'/> <inherits name='com.google.gwt.user.theme.standard.Standard'/> <entry-point class='com.cadao.client.platform'/> <stylesheet src='platform.css' /> </module>
I thought I got passed this kind of errors, but obviously not. Please help. Thanks a bunch.
-
6 Jan 2009 5:42 PM #2
1st - java.sql.Connection won't be able to be imported into a GWT client app and won't compile even if you fix this
2nd - com.cadao.server.CadaoDb is in the server package - only classes in the client package are visible to the GWT compiler.
These are GWT issues, not GXT.GXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
6 Jan 2009 10:58 PM #3
gslender,
For security reason, I need two separate applications. A new person needs to register an account. This is the first application. A registered person uses a second application to access stuffs I do not want non-registered people to hack into. Both will need to talk to DB. How do I factor out the RPC codes that contact DB and reference in both applications? From your explanations, it looks like I need to repeat RPC codes in both apps. Any hints? Thanks.
-
7 Jan 2009 12:04 AM #4
yup... simply create another GWT source path/package and add this to your gwt.xml
com.cadao.client <-- your gwt client side UI classesCode:<source path="data"/> <source path="client"/>
com.cadao.data <-- your gwt/server pojo classes
com.cadao.server <-- your server side servlet classesGXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
7 Jan 2009 1:31 AM #5
gslender,
Are you saying that I need to repeat the RPC codes in both apps, or are you saying that I can factor out and use source tag to include them. I did some research on how to use source tag, it looks like factoring is not possible.
http://code.google.com/p/google-web-...thsHandlingFAQ
Thanks.
-
7 Jan 2009 2:02 AM #6
you'll need to explain more clearly what you are trying to do.
your original issue was GWT compiling and getting an error regarding a class that isn't in the source path of the compiler - com.cadao.server.CadaoDb
the comment regarding two applications/security is irrelevent and confusingGXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
7 Jan 2009 6:47 PM #7
gslender,
I fixed the package scope issue by dropping the database classes directly into my com.cadao.server package that has my RPC implementation. That seems to work, but I now get an exception relating to java.sql.Connection as you predicted. I searched the forum but could not find any hint on what connection package I should import. What kind of connection package should I import? Or how to fix this code so that I can talk to the MYSQL database? Thanks.
[ERROR] Line 11: No source code is available for type java.sql.SQLException; did you forget to inherit a required module?
Here is the code:
Code:package com.cadao.server; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; public abstract class Db { private String driver = "com.mysql.jdbc.Driver"; /** * Constructor */ public Db() { } protected abstract String getUrl(); protected abstract String getDb(); protected abstract String getUser(); protected abstract String getPassword(); public final Connection getConnection() { String url = getUrl(); String db = getDb(); String user = getUser(); String password = getPassword(); Connection connection = null; try { Class.forName(driver).newInstance(); connection = DriverManager.getConnection(url + db, user, password); } catch(Exception e) { System.err.println("Mysql Connection Error: "); e.printStackTrace(); } return connection; } protected static int getResultSetSize(ResultSet resultSet) { int size = -1; try { resultSet.last(); size = resultSet.getRow(); resultSet.beforeFirst(); } catch(SQLException e) { return size; } return size; } }
-
7 Jan 2009 6:56 PM #8
I think you need to think a little more high level about what you are trying to do.
GWT is a client (browser) application that results in Java code being compiled to Javascript. There is no connection to your server unless you explicitly make one - ie there is no way to SQL connect to the DB in GWT using Java objects - ie you can't just "talk to the MYSQL database"
RPC, XML and JSON are common methods to transfer data between the client and web server using HTTP (this is a GWT concept and nothing to do with ExtGWT) - you need to wrap transfer and marshalling code around this to actually perform the concept of querying and updating data. What you do at the server side (ie Servlet container) is up to you, and again GWT doesn't anwser this problem or provide a solution.
I'd encourage you read more about GWT or perhaps consider buying a book on the subject as clearly this fundamental concept needs to be fully understood before you even design the application UI - which is what ExtGWT offers.GXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender
-
7 Jan 2009 7:10 PM #9
gslender,
Making explicit RPC to the server is what I am doing. Here is what I am trying to do and how:
- I need to check if the entered SSN already exists by calling function isDuplicate(...) function, which is an RPC implementation and resides on the server side (*Impl.java) in a package called com.cadao.server of my application. isDuplicate(...) needs to talk to database to check username and password. I, therefore, dropped the database classes such as Db.java and Cadao.java into the com.cadao.server package of my application (a different application, not platform application that we discussed in the thread) to make the connection. So, it's all on the server side. Sorry for not being clear.
- I hardcoded isDuplicate(....) and made sure that isDuplicate(...) function already worked.
Thanks gslender.
-
7 Jan 2009 7:35 PM #10
My advice still stands - read more about GWT and RPC.
ie - you can't transfer ANY kind of object you like via RPC. The Java objects need to be able to survive GWT JRE library emulation and there is only a limited type of Java objects that can... eg POJO's are fine. A java.sql.Connection object is not.GXT JavaDocs: http://extjs.com/deploy/gxtdocs/
GXT FAQ & Wiki: http://extjs.com/learn/Learn_About_the_Ext_GWT_Library
Buy the Book on GXT: http://www.apress.com/book/view/9781430219408
Follow me on Twitter: http://twitter.com/gslender


Reply With Quote