I am a newbie at GWT and I have the following query.
I have a scenario where I am trying to develop a web interface(using GWT) for an existing application.
In the client side class file I would like to invoke a user specific class file, i understand that this is due to the fact that i am trying to invoke classes other than the ones http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html
I would like to know how this code can be called from the client side of the ui.
Thanks and Regards,
Bhavya
If you have a source code for the class you want to use and it is using only the supported Java classes, you can simply add your specific classes to client packages. If this is a reusable code, you can create a new GWT module and inherit it in your application. You can also simply move those classes to your client packages OR add a new client folder in you .gwt.xml file (add one more <source> tag)
If your class is not compilable by GWT, then I think you need to use it through RPC service.
If the code is translatable into JavaScript, you could for example put your individual class files into a jar and add it to the Build Path - as you would do in a 'regular' Java Project.
Related
I'm using the regular GWT project structure that is generated when creating a new GWT project via the Eclipse GWT plugin, e.g. com.mycompany.mygwtmodule.client for all the client stuff that is GWT-compiled into JavaScript.
Now I want to add some client code with a custom package structure, e.g. org.othercompany.somepackage...
Is that doable? And, if so, how?
I don't need a workaround, if it's not doable. However, it may still be helpful for you to know, why I want to do this: The custom package structure is from a 3rd-party GWT module that is used by my GWT project. I just need a small set of classes from it which I copied into my project instead of including the whole module which contains lots of stuff I don't care about. Those classes are using each other. As I do not want to touch their code at all, I am keeping their original package structure.
What I tried is to add <source path='my-eclipse-project-path/src/org/othercompany/somepackage'/> to my gwt.xml, but in hosted mode I'm getting the error: "No source code is available for type org.othercompany.somepackage.SomeClass; did you forget to inherit a required module?"
No, I didn't ;-) The code is all there, but I couldn't make GWT find it.
Thanks for any helpful comments!
Its Better you create two separate modules ,since you are taking the code from some other 3rd party jar.
First create module which contain the package structure
- com.mycompany.mygwtmodule (one module)
Second create another module
-org.othercompany.somepackage (another module)
Inherit the second module in first module.gwt.xml
<inherits name="org.othercompany.somepackage" />
You need to add the other source package in your sources.
This is done in your module.gwt.xml. There is an element source, that will list all source packages to be included for client:
<source path="client" />
<source path="shared" />
will include all packages in client and shared into the frontend code.
Details can be found here: http://www.gwtproject.org/doc/latest/DevGuideOrganizingProjects.html#DevGuidePathFiltering
Update: if your packages have no common package you need to create two seperate modules and one inherits the other.
We use this a lot, it works out very nice.
I'm developing a GWT project at the moment and it's been up and running for a while. New functionality that is to be added require extensive testing, visualizing and simulating of a specific algorithm. I would like to export that specific algorithm so that I may call it directly from JavaScript and do some canvas magic.
How can I export a number of classes for direct use in JavaScript from a GWT project?
I've tried using the GWT exporter, following the Getting Started section closely.
I've noticed that my output directory contains a new generator class (TestClassExporterImpl.java) but the final JavaScript output contains no trace of my TestClass or the exported methods.
I'm sure I've made a mistake somewhere on the way or didn't understand the GWT exporter correctly.
Try to disable obfuscation, it will create the same names in Javascript as in the original Java code
I've a command line Java program that uses multiple folders containing files representing models, indices and resources that are loaded and used by some of the Java classes at runtime.
I'm trying to convert this program to a Play application (Scala) to provide a RESTFul interface. My question where should I put these folders so that they will be accessible by the Java classes when my Play application is running?
I'm using play-2.1.4.
you can add folder to classpath via SBT ( check out sbt document ),
so playframework can find you class, and then create some play action to reuse the service which you already have.
and, if you just want to wrap your application to provide some REST API, I'd like to recommend Spray to you, which can make your application export as REST API more easy. Hope this helps.
I have a gwt library which I include to my other project via:
inherits name="org.mylib.Mylib" />
All the classes in the library project is under org.mylib.client*
This works fine.
However I added packages that contains classes that I want to be included in the library, i.e to be called within a GWT client side code.
Will it work if I don't put the classes under org.mylib.client?
Packages like: x.io, x.nio etc. to be usable within a GWT client side code.
They need to be Java source files, not just classes. You may have meant this, but that part of your question is ambiguous.
Assuming they are sources, you do need to include them in a package that you've declared to GWT contains sources. Either by inheriting a module which has this, or by adding it yourself in your main module. In short, somewhere you need this:
<source path="/mySourcePath" />
where /mySourcePath is the location of the sources for this x.io pckage.
I'm trying to build database application using GWT 1.5.3. I use JPA annotations with my objects. It seems in hosted mode GWT's RPC works fine. But when I try to compile my app using GWT-compiler I get errors like: "The import javax.persistence cannot be resolved", "Entity cannot be resolved to a type". toplink-essentials.jar is already included in my project path. What settings else do I need to solve this problem?
You can use Gilead (http://sourceforge.net/projects/gilead/) library to seamlessly manage JPA entities with GWT.
Regards
You need to include the source code for the JPA annotations in the build path for your GWT project. See here for more details:
http://code.google.com/p/google-web-toolkit/issues/detail?id=1830&can=1&q=jpa
Specifically this jar file which will fix your problem:
http://google-web-toolkit.googlecode.com/issues/attachment?aid=1475633892125294312&name=jpa-annotations-source.jar
The general problem of the JPA and GWT is that GWT itself doesn't support fancy JPA classes, so you just do simple POJO persistent entities DTO that implements the java.io.Serializable and have simple JPA resource annotations. You need to create the entity classes in the scope of the GWT client either have it under the yourproject.client package or add them with
source path="client"
source path="folderOfYourEntities"
in the GWT project's YouProject.gwt.xml file. This will include the entity objects in the GWT client so they can used them on client side of the RPC as well. The DAO must be on the server side and can contain anything that you container supports.
The problem you have now is that when compiling, GWT compiler saids that it desn't know what those imports for JPA annonations are in the entity DTO classes. That is why you need the javax.persistence class and source codes. The jpa-annotation-source.jar reference by Rustmyself works. It is just the javax.persistence compiled class files and source codes files plus a Persistence.gwt.xml. It is a simple GWT module for the javax.persistence package. If you know how to make your own GWT module, you should have problem making all this work. By the way, the official source for the Java EE can be found on the glassfish dev site's build section wiki.glassfish.java.net
There are many other solutions that wrap your fancy PU entities to simple objects automatically using proxy or to lazy load them at run time. They work, but not optimal solutions. The best practice is to make things simple and robust from the start by having POJO JPA DTO entities on the GWT client context and full blown DAO on the server.
GWTPersistence Example
I have added an actual working example on how to make GWT and JPA work seamlessly. It is a NetBean project with source codes and deployment file. See GWTPersistence on NingZhang.info
Ok, I've found what I was missing. I needed to include jpa-annotations-source.jar in my GWT-compiler path in myapp-compile.cmd script (or in ant build file). By the way can anyone tell me the origin of this jpa-annotations-source.jar file?
I am also working with JPA <--> GWT data transformation etc.
In an effort to eliminate the DTO layer I used Gilead too.
My objection here is about translating javax.persistence. To avoid this I used XML JPA mapping declarations (orm.xml)
Simply, keep another version of your Entities but without the annotations!
Rebounding on synergetic's comment, you now (from GWT 1.5) only need to add
<source path='javax.persistence'/>
to your Module.gwt.xml