Wednesday, September 13, 2017

Re: How do you use GWT "Genertor" class?

Thank you so much. It helps a lot.

On Wednesday, September 13, 2017 at 2:56:54 AM UTC-7, Thomas Broyer wrote:


On Wednesday, September 13, 2017 at 6:17:07 AM UTC+2, Ananchai Srirochanakul wrote:
Hi there,

I have questions about this "Generator" class below. The code below is the one that generate the GWT Sample page, that you can see here http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCheckBox.
I have been looking at such code for some time now. I notice it would generate many Java.html files, in this location "/war/showcase/gwtShowcaseSource".

First, see http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsDeferred.html#generators for more information about generators in GWT and how they work.
Note however that deferred binding (as a whole, and generators in particular) are strongly discouraged for any new development; you're encouraged to move to if/else or switch/case with System.getProperty() (though I must say I'm not sure it's ready yet to completely move to that, and <replace-with> rules might still be needed) and annotation processors or other forms of code generation.
 
My questions to you are below.

1. If I export the project that uses this "Generator" class as the war file, and upload such war file to Tomcat server, when the users use the website, will they be able to read the source code? I really don't want any users that come to my website to be able to view any Java source code, because of the safety issue.

It all depends if you actually trigger the generator in your code with a GWT.create(), and it would be limited to files matching this generator's requirements (apparently classes extending ContentWidget, though I only skimmed the code)
 
2. Why would anyone want to use this "Generator" class to generate another set of Java source code?

This specific generator is meant for displaying examples' source code alongside the examples in the Showcase: click the "CSS Style" and "Source Code" links/tabs at the top of http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCheckBox, click "Example" to switch back to the live example.
This is a specific need for the Showcase, and it's not meant to be reused anywhere else.
 
I am guessing, at this point, that you would do this if you want to implement "GWT Localization" such as supporting multiple languages. But, then, you would be generating source code for people to see.

Internationalization indeed makes use of generators, but those a different ones. Please refer to http://www.gwtproject.org/doc/latest/DevGuideI18n.html for more about i18n.

 
3. I hope someone can explain to me the life cycle of this "Generator" class. From how I understand it, during the "Dev" mode, using Eclipse, it would be compiled by Java Virtual Machine. However, once you export the project as the war file and upload it to the server, it would be used as Javascript library. But why you would need to include these raw files within the war file?

The generator itself is called by the GWT Compiler (including when running in dev mode). Things that are generated can either be used as new source in the compilation, or public resources that will be output next to the generated JS code.
In this specific case, the generator only actually generates public resources. The i18n generators would only create new source, used during the current compilation and never seen by anyone else (they're not even written to disk by default, only kept in memory)

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment