Internationalization in Google Web Toolkit - gwt

I want to use the internationalization for my GWT Application.
I read that i need a Languages.properties file in which I write for example ticketHomeSiteLabelDemnaechst="Activities due soon"
a class which i called Languages.java:
import com.google.gwt.i18n.client.Messages;
public interface Languages extends Messages{
String ticketHomeSiteLabelDemnaechst();
}
applicationname.gwt.xml:
<inherits name='com.google.gwt.i18n.I18N'/>
<extend-property name="locale" values="de"/>
<extend-property name="locale" values="en"/>
<set-property-fallback name="locale" value="en"/>
And in the class where I want to use it:
final Languages language = GWT.create(Languages.class);
labelDemnaechst.setText(Int.get(language.ticketHomeSiteLabelDemnaechst()));
When I do this:
I get this error: No source code is available for type Languages; did you forget to inherit a required module?

The error message indicates that Languages.java may be in the wrong package. Make sure it is in the client package, assuming that is where you keep your other gwt code (the EntryPoint, and whatever the last code snippet came from).

Related

GWT: No source code available for type java.io.ByteArrayOutputStream

I have a class in my shared package which have this ByteArrayOutputStream
But still getting this exception.
Any idea whats the reason and what could be the solution
No source code is available for type java.io.ByteArrayOutputStream; did you forget to inherit a required module
My xml class
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
Thanks
You are probably trying to use java.io.ByteArrayOutputStream on the GWT client side, which gets compiled out into javascript. Because of this, only a subset of the java classes are supported for use on the client side.
To see which classes are supported on the client side, see here: http://www.gwtproject.org/doc/latest/RefJreEmulation.html

Inject to custom ConstraintValidator in gwt

I am trying to write a custom ConstraintValidator for gwt and inject an implementation of an interface into it.
Is this even possible?
Here is my solution.
Turns out that you cannot inject a gin managed class into a generated class.
The way I solved it was using the info in the following link:
https://groups.google.com/forum/?fromgroups=#!topic/google-web-toolkit/rN476RgdGAM
and had to write/extend the ValidatorGenerator from gwt.
Lttle bit of work
<generate-with
class=".... CustomValidatorGenerator">
<any>
<when-type-assignable class="javax.validation.Validator" />
<when-type-assignable
class="com.google.gwt.validation.client.impl.GwtSpecificValidator" />
</any>
</generate-with>

Can't return custom class from GWT Service

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.

Error In Internationalize a GWT UIBinder page with Messages

We are using GWT & GWTP with UiBinder and I want to use properties files for messages.
I have seen GWT app with UiBinder and This one also.
1) Entries In gwt.xml file
<extend-property name="locale" values="en"/>   
<set-property-fallback name="locale" value="en"/>
 2) In LoginView.ui.xml
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:fmt="ui:with:com.nextenders.client.properties.NTCommonPropeties"
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales="en">
I have created a file and interface and added in Xml.
<ui:with field='fmt' type='com.nextenders.client.properties.LocalizableResource'/>
Now I am trying to use
Now I am trying to compile with "-extra" option.
But I am getting "No resource found for key" error.
In which order need to go through all the steps described here.
I mean Should I set messages after compile.
UPDATE: I have removed
<g:Label text="{fmt.loginBoxTitle}" styleName= "login_label" />. But Still It give same error when I compile.
I have found the solution. The error "No resource found for key means GWT compiler is not able to find mapping for the key you have specified. E.g. loginBoxTitle in my {fmt.loginBoxTitle}
I have rechecked files for mappings. It worked.

Mapping ui:field in GWT to generated code

I'm trying to get some automated UI testing going on a GWT application and I'm having trouble finding a way to track UI elements.
For example, I have the following:
<g:Button text="Submit" ui:field="submitButton" enabled="true" />
which generates:
<button class="gwt-Button" type="button">Submit</button>
Its a compiler error to set both ui:field and id (id is considered deprecated anyway) so the problem is that I have no easy way to select my submit button using something like selenium.
Is anyone aware of a way I can map the
ui:field="sumbitButton"
to the generated HTML?
After further investigation I've discovered that you can enable debugIds which are ment for testing purposes. If you add:
<inherits name="com.google.gwt.user.Debug"/>
to your *.gwt.xml file you can then set debugId on your ui elements as such:
<g:Button text="Submit" ui:field="submitButton" enabled="true" debugId="submitButton"/>
and also in the codebehind by using the ensure debug id method
submitButton.ensureDebugId("submitButton");