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.
Related
anybody knows how to check if a js/css file is already included with typoscript?
Example
[Template_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
now if i got an extension with the same include e.g.
[Extension_A.ts]
page.includeJS {
jsfile = fileadmin/Template/js/jquery-1.10.2.min.js
}
Is there a way to prevent this kind of double code injection? Maybe i got another Template e.g. Template_B.ts where jquery is not included - than the Extension_A.ts has to include jquery by itself.
Kinldy
You can use the same key inside includeJS such it just gets overridden if you include the file twice.
Other than that you should put jQuery into includeJSlibs, such that it is loaded before the other JS files.
Other than that, the TS should be unique for each page. Therefore you always to make sure anyway that all resources are included in-order.
You should not include JS libs with the automatic extension TS setups. Use your documentation to tell the integrator what needs to be included and what not.
The various and independent inclusion of scripts by plugins and templates is one of the tricky points in TYPO3. As far as I know, this point cannot be managed at one single point.
There is a plugin "t3jquery" that offers to build, compress and share a common jQuery library. It also has a service to analyze other plugins for their dependencies. But this doesn't solve the problem in general, as many plugins don't check for libraries already loaded.
The most stable way is to remove all plugin's references to libraries manually in your TypoSkript. This gives you some simple additional TypoSkript lines. I use lines like these:
plugin.tx_imagecycle_pi1.file.jQueryLibrary >
plugin.tx_imagecycle_pi1.jQueryLibrary >
plugin.tx_multicontent_pi1.file.jQueryLibrary >
plugin.tx_multicontent_pi1.jQueryLibrary >
# Fluid
page.headerData.998 >
You can find the matching TypoSkript descriptors by searching for the library name in the TypoSkript browser or by greping in the plugin's source code. You will also need this if you wish to add libraries as part of content that was get by AJAX, thus separating the libs from the page content.
Here's a tut (in German): http://jweiland.net/typo3/typoscript/javascript-manuell-entfernen-oder-einbinden.html
Futher possibilities you can check:
Some plugins are written in good structure and offer to keep back their Javascript in the settings.
Some script inclusions may come rather from the static template but from a plugin, so don't forget to have a look there.
I have my GWT project, and another project that just has simple Domain Objects, and has nothing GWT specific.
In my Domain Objects project, I have a class Bob that has some primitive fields. Nothing special. He implements Serializable for the hell of it.
I wanted to return this type from a GWT service method. Learning that the service method can only return classes that implment GWT's IsSerializable interface, I created a subclass of Bob, BobSO (Bob Service Object), and had it implement IsSerializable.
Basic project structure
proj> Bob.java
proj_gwt
proj_gwt > projgwt.gwt.xml
proj_gwt.client
proj_gwt.server
proj_gwt.shared > BobSO.java
I'm getting an error when running the service. It seems that it's loading BobSO, and seeking the source for the superclass Bob, and can't find the source.
"Errors in [path to file]
Line 6: No source code is avaiable for Bob did you forget to inherit a required
Will by BobSO subclass work since he implements IsSerializable?
It looks like GWT knows where BobSO is. What do I need to do to so it knows where the source to Bob.java is? I've tried creating a gwt.xml in my DOmain Objects project, but I'm not sure if it needs to list each class that should be visible, and how to import it in my GWT project.
1. Serializability
Implement either Serializable or IsSerializable, plus make sure, that the class fulfills the remaining requirements for GWT serializability (a no-args constructor, no final fields, ...)
2. Locating the sources
You need to create a module to help GWT-RPC find the serializable classes [*].
The module "gwt.xml" can live in your domain project. Alternatively, if you you don't want to touch the domain project, it can also live in your GWT project - just make sure to put it in the correct package:
DomainProject
src
bar
domain
Bob.java
GwtProject
src
bar
Domain.gwt.xml (contains <src path='domain'/>)
foo
client
MyEntryPoint.java
shared
BobSO.java
Bar.gwt.xml (contains <src path='client'/>
<src path='shared'/>
<inherits name="foo.Domain"/>)
Important notes
Make sure to delete the gwt-unitCache folder after changing such dependencies. Otherwise, the compiler often fails in strange ways (tested with gwt 2.5.0.rc2).
Always supply the source folders to the GWT compiler for everything the client side needs to know about. In this case, this is also the source for bar.domain.Bob.
Note
It's also possible to put Domain.gwt.xml in the "bar/domain" package, and use <source path=""/>
[*] By the way, it may be surprising, that defining a module for the dependency is usually not even strictly necessary in GWT. (It is however required when GWT-RPC is involved.) Try it with a simple example, if you like - GWT will find the sources by itself - as long as they're on the GWT compiler's class path
Will by BobSO subclass work since he implements IsSerializable?
It should work, but note that IsSerializable is the "old" marker interface for GWT. You can now use java.io.Serializable instead.
It looks like GWT knows where BobSO is. What do I need to do to so it knows where the source to Bob.java is? I've tried creating a gwt.xml in my DOmain Objects project, but I'm not sure if it needs to list each class that should be visible, and how to import it in my GWT project.
I think that creating a GWT module in your domain project is the right approach. You don't have to list each class. The "path" attribute of the "source" element should contain the name of a child package:
<module>
<source path="mysubpackage" />
</module>
You can have more that one source element if you have multiple packages. You can also include/exclude specific classes from a package, e.g.:
<source path="somepackage">
<include name="SomeClass.java" />
<include name="stuff/OtherClass.java" />
<exclude name="blah/**" />
</source>
To import it in your original GWT module, simply add an "inherits" entry with the fully qualified name of the .gwt.xml file you created, but without the ".gwt.xml" extension. Assuming your new module file is called Domain.gwt.xml and is located in package "com.domainpackage", you would add:
<inherits name="com.domainpackage.Domain" />
You can package your project as a jar and add it to the class path of your GWT project.
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 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.
I have developed one GWT project . I have created one JPA entity called Employee. I want that entity to be persisted to the database. My Employee is
located under com.mygwt.client.bean. Now my question is that are all the entities meant to be located at server side? When I tried to create under
the server side I got the exception saying Forgot to inherit the module for the Employee. Is there any other way for creating the entities in server side instead of creating the entity in client side? Please suggest the way I am doing right or not.
Put in the server side and then add an additional <source path='..'/> to your .gwt.xml to tell GWT where the sources are.
The above answer is right. But you have to be careful what you put in the packages you add using <source path='..' />. The tag <source path='...' /> in your project gwt.xml file tells the GWT compiler where to look for client side-code to convert to JavaScript. So you can only put classes in there that can be converted to JavaScript. You can not just add the server-side package which contains your remote servlets, that is wrong and won't work.
I suggest the following structure:
com.mycompany.client
com.mycompany.shared
com.mycompany.server
Basically client code is in the client directory, and in shared you keep classes (transfer objects, models, validators...) which are used client-side and server-side. Then put these lines into the project gwt.xml file:
<source path='com.mycompany.client' />
<source path='com.mycompany.shared' />
You'll have to be careful to access the server library jars only from the com.mycompany.server tree.
Also, not try to send an object from the server libraries over the wire to the client. If you need to send server library objects over the wire you'll have to have the source to the library -- it's a mess. It is easier to create a DTO class in com.mycompany.shared that is created my the sevrlet of your application from the server side information.
Stuart