|
Documentation for the GWT 2.0 release of ClientBundle can be found on the GWT Developer's Guide website. IntroductionThe resources in a deployed GWT application can be roughly categorized into resources to never cache .nocache.js, to cache forever .cache.html, and everything else myapp.css. The ClientBundle interface moves entries in the everything-else category into the cache-forever category.
Goals- No more uncertainty if your application is getting the right contents for program resources.
- Decrease non-determinism caused by intermediate proxy servers.
- Enable more aggressive caching headers for program resources.
- Eliminate mismatches between physical filenames and constants in Java code by performing consistency checks during the compile.
- Use 'data:' URLs, JSON bundles, or other means of embedding resources in compiled JS when browser- and size-appropriate to decrease the number of round-trips entirely.
- Provide an extensible design for adding new resource types.
- Ensure there is no penalty for having multiple ClientBundle resource functions refer to the same content.
Non-Goals- To provide a file-system abstraction
ExamplesTo use the ClientBundle, add an inherits tag to your gwt.xml file: <inherits name="com.google.gwt.resources.Resources" /> Interfaces: public interface MyResources extends ClientBundle {
public static final MyResources INSTANCE = GWT.create(MyResources.class);
@Source("my.css")
public CssResource css();
@Source("config.xml")
public TextResource initialConfiguration();
@Source("manual.pdf")
public DataResource ownersManual();
}You can then say: Window.alert(MyResources.INSTANCE.css().getText());
new Frame(MyResources.INSTANCE.ownersManual().getURL()); I18NClientBundle is compatible with GWT's I18N module. Suppose you defined a resource: @Source("default.txt")
public TextResource defaultText();For each possible value of the locale deferred-binding property, the ClientBundle generator will look for variations of the specified filename in a manner similar to that of Java's ResourceBundle. Suppose the locale were set to fr_FR. The generator would look for files in the following order: - default_fr_FR.txt
- default_fr.txt
- default.txt
This will work equally well with all resource types, which can allow you to provide localized versions of other resources, say ownersManual_en.pdf versus ownersManual_fr.pdf. Pluggable Resource GenerationEach subtype of ResourcePrototype must define a @ResourceGenerator annotation whose value is a concrete Java class that extends ResourceGenerator. The instance of the ResourceGenerator is responsible for accumulation (or bundling) of incoming resource data as well as a small degree of code generation to assemble the concrete implementation of the ClientBundle class. Implementors of ResourceGenerator subclasses can expect that only one ResourceGenerator will be created for a given type of resource within an ClientBundle interface. The methods on a ResourceGenerator are called in the following order - init to provide the ResourceGenerator with a ResourceContext
- prepare is called for each JMethod the ResourceGenerator is expected to handle
- createFields allows the ResourceGenerator to add code at the class level
- createAssignment is called for each JMethod. The generated code should be suitable for use as the right-hand side of an assignment expression.
- finish is called after all assignments should have been written.
ResourceGenerators are expected to make use of the ResourceGeneratorUtil class. Potential pitfalls- Changing the content of the resources will change the filenames (or data: encoding), thus forcing a recompile of the GWT application. To avoid this, the inlining and renaming features can be globally toggled off in your gwt.xml file during the development phase.
- Inlining files into the compiled JS may not make sense if those files are not always accessed by the program, thus inlining should be configurable on a per-resource or per-ClientBundle basis.
Levers and knobs- ClientBundle.enableInlining is a deferred-binding property that can be used to disable the use of data: URLs in browsers that would otherwise support inlining resource data into the compiled JS.
- ClientBundle.enableRenaming is a configuration property that will disable the use of strongly-named cache files.
Resource typesMigrating from ImmutableResourceBundlePlan- Expected that incubator IRB system will initially co-exist with ClientBundle in trunk while integration issues are worked out.
- Will then change incubator code to add deprecations.
- No plans to remove types from incubator for long period of time.
- No additional features or bug-fixes will be added to incubator APIs.
Changes- Package changed to com.google.gwt.resources
- Inherit com.google.gwt.resources.Resources
- Renamed ImmutableResourceBundle to ClientBundle
- Renamed @Resource annotation to @Source
- Map-style methods moved to ClientBundleWithLookup
- Switched most gwt.xml properties to be configuration properties instead of deferred-binding properties
- Some gwt.xml properties have changed names:
- ResourceBundle.* to ClientBundle.*
- CssResource.enableMerge to CssResource.mergeEnabled
- CssResource.forceStrict to CssResource.strictAccessors
- CssResource.globalPrefix to CssResource.obfuscationPrefix
- CssResource.style has changed to a configuration property; switch from <set-property> to <set-configuration-property> tags to configure this.
- StyleInjector moved to com.google.gwt.dom.client package
|
When i try to inherit com.google.gwt.resources.Resources, i get:
So i guess im missing a jar of some sort. Where is the Resources module jar located? and where can i download it?
That's because you're not using GWT 2. The Resources module is part of GWT 2 and is located as expected at com/google/gwt/resources.
But the download area dosent have a link to GWT2 its pointing to GWT1.7
I am having the same problem. any resolution to this?
Thank you
GWT 2 isn't done yet. There is a preview release in the downloads area, 2.0-ms1, but you'll note that it's marked deprecated to as a warning that it is not intended for production use, and that its API will certainly shift. Or you can build from svn trunk, keeping the same disclaimers in mind.
Thank you! One follow-up question: Can I only use the ClientBundle with GWT1.7.1?
No. You can use the ClientBundle's predecessor, the incubator's ImmutableResourceBundle?, with pre-2.0 builds. ClientBundle is part of GWT 2.0.
http://code.google.com/p/google-web-toolkit-incubator/
Hi, is there any example how to use ClientBundle for images that need to be repeated (repreat-x for example) as background. At the moment i do it with css like this: .bg-repeat {
}But with this i am not using ClientBundle and i have many images that must be used this way, so my UI performance will decrease. Please give me example how to do it? This ImageOption? repeat seems to stretch the image not repeat it, but i can't do it even with it.
I am trying to use the ClientBundle. I have got a inherit for Resources in my gwt.xml. I have a public folder at the same level as my gwt.xml and which contains an images folder. Finally I have an interface extending the ClientBundle as follows:
public interface AppBundle extends ClientBundle { public static final AppBundle INSTANCE = GWT.create(AppBundle.class); @Source("com/tech/keswick/web/public/images/organisnew.gif") public ImageResource add_org();but it is showing error Resource file organisnew.gif is missing (expected at com/tech/keswick/web/public/images/organisnew.gif)
I used this with ms1 and it did not use to complain.
May be you should place the resources in some package not in the public folder.
@nenchev You want to add the following annotation to your x/y repeating images @ImageOptions?(repeatStyle=RepeatStyle?.Horizontal) This will generate up to three bundled images, one for vertical repeat, one for horizontal repeat, and the last for static sizing. Of course, unless you disable inlining, this will only be used for non-data URI IE compiles.
@shahidzaman, Nenchev is correct. Source files for bundles must be in client-accessible packages. If you want to use the bundle, but you also want to copy the images to /war for deployment purposes {redundant and I don't like it, but that doesn't mean you don't have a good reason to do so}, you can use a second .gwt.xml file which sets the client source path to public, so files in that folder will be source files, AND copied to war.
I have stuff like `<source path="shell"/> <inherits name="x.y"/> <source path="client"/>` in most of my modules. x.y is where I put RPC classes to shorten the Strings sent over the wire. You could do the same, just change shell to public, and in the middle, you have to inherit something, preferably something that sets source path="client" at the top of the module, or else you might get weird errors. com.google.gwt.user.User is a good one.
Not able to re-size the image with ClientBundle. Is there any way to achieve this?