Deferred binding failed GWT using uibinder - gwt

Below are the total files used in project. It is giving these errors
[ERROR] [cricketscore] - Deferred binding failed for 'test.client.UserDashboard.MyUiBinder'; expect subsequent failures
and
[ERROR] [cricketscore] - Unable to load module entry point class test.client.DashBoard (see associated exception for details).
Please help me resolve the problem in it.
Cricketscore.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.0//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='cricketscore'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<!-- Specify the app entry point class. -->
<entry-point class='test.client.DashBoard'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
Dashboard.java
package test.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
public class DashBoard implements EntryPoint{
#Override
public void onModuleLoad() {
RootPanel.get().add(new UserDashboard());
}
}
UserDashboard.ui.xml
<!-- UserDashboard.ui.xml -->
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:my='urn:import:test.client' >
<g:HTMLPanel>
<my:CricketScores ui:field='scores' teamNames='AUS, SAF, WA, QLD, VIC'/>
</g:HTMLPanel>
</ui:UiBinder>
CricketScores.java
package test.client;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.user.client.ui.Composite;
public class CricketScores extends Composite{
public #UiConstructor CricketScores(String teamNames) {
this(teamNames.split("[, ]+"));
}
public CricketScores(String... teamNames) {
// TODO Auto-generated constructor stub
}
}
UserDashboard.java
package test.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
public class UserDashboard extends Composite {
interface MyUiBinder extends UiBinder<Widget, UserDashboard>{}
private static final MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
private final String[] teamNames;
public UserDashboard(String... teamNames) {
this.teamNames = teamNames;
initWidget(uiBinder.createAndBindUi(this));
}
#UiFactory CricketScores makeCricketScores() {
return new CricketScores(teamNames);
}
}

You have conflicting information in your code: a #UiConstructor and a #UiFactory (not conflicting actually, there's an order of precedence, but it can be confusing to the developer, i.e. you).
UiBinder will prefer the #UiFactory over the #UiConstructor, and your factory has no argument, so the teamNames attribute from your XML is tentatively mapped to a setTeamNames setter, which doesn't exist, hence the “Class CricketScores has no appropriate setTeamNames() method” error.
The problem is conceptual in your code: your UserDashboard is constructed with a list of team names that it passes to the CricketScores widget, so that widget shouldn't have a teamNames attribute in the XML.

I was getting same error and uiField(provided=true) was getting null but it got resolved when I created object of respective component in constructor

Related

UiBinder variables

I am fitting with UiBinder in gwt. I am using collapse uibinder (bootstrap library). I have the follow code:
<b:Collapse b:id="toggle1" existTrigger="true" ui:field="toggle1">
<b:FluidRow>
<b:Column size="12">
<b:Alert close="false" animation="true" heading="Cabecera">
Text
</b:Alert>
</b:Column>
</b:FluidRow>
</b:Collapse>
My problem is I need change the b:id="toggle1" when I create it. I need use variable. Could someone explain me how to do it? I have looking on internet but I did not find a good explanation
Thank you very mucho in advice.
Set ID in JAVA after calling createAndBindUi().
collapseWidget.getElement().setId("toggle2");
Steps to follow:
Add below entry in you gwt.xml
<inherits name="com.google.gwt.user.Debug"/>
Use debugId along with ui:field as shown below in your ui.xml
<gwt:CheckBox ui:field="myCheckBox" debugId="myCheckBox" />
Now you can get the Id
myCheckBox.getElement().getId();
All the Ids are generated with default prefix gwt-debug- as shown below. If you want then you can remove it.
gwt-debug-myCheckBox
Use any one getElement().setId() or ensureDebugId(). The difference between them is prefixing with gwt-debug-. ensureDebugId() uses prefix.
Sample code: (Setting ID of cancelButton dynamically)
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;
public class MyDialogbox extends DialogBox {
private static MyUiBinder myUIBinder = GWT.create(MyUiBinder.class);
#UiTemplate("MyDialogbox.ui.xml")
interface MyUiBinder extends UiBinder<Widget, MyDialogbox> {
}
public MyDialogbox() {
setWidget(myUIBinder.createAndBindUi(this));
System.out.println(cancelButton.getElement().getId());
cancelButton.getElement().setId("cancel");
}
#UiField
Button cancelButton;
#UiHandler("cancelButton")
void doOpenDialogBox(ClickEvent event) {
hide();
}
}
MyDialogbox.ui.xml
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:DialogBox autoHide="true" modal="false">
<g:caption>
<b>Caption text</b>
</g:caption>
<g:HTMLPanel>
Body text
<g:Button ui:field='cancelButton' debugId='cancelButton'>Cancel</g:Button>
<g:Button ui:field='okButton' debugId='okButton'>Okay</g:Button>
</g:HTMLPanel>
</g:DialogBox>
</ui:UiBinder>

make work an applet in a osgi bundle

I would like to create a web application that performs some sort of animation of some bundle's activity inside an OSGI Framework. I'm using Equinox embedded in Tomcat through Servletbridge. I have tried to create an OSGI bundle that registers an HTML page (with an applet tag) using httpservice. The OSGI bundle contains a package with the applet class.
When I export the plugin project in the tomcat/webapps/bridge/WEB-INF/eclipse/plugin directory the jar content is:
META-INF
META-INF/MANIFEST.MF
name/of/packages/.class files
home.html
In the activator class of this bundle I get an httpservice and register the home.html file as /home. When I start Tomcat and go to:
localhost:8080/bridge/home
The page loads, but I get a ClassNotFoundException on the applet, whereas opening the HTML page from the Jar archive the Applet load. How can I make it work?
edit:
home.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<applet code="thesis.bot.wab.applet.DApplet.class" width="400" height="250"></applet>
</body>
</html>
src/thesis.bot.wab.Activator
public class Activator implements BundleActivator {
private static boolean started=false;
HttpServiceTracker http;
public void start(BundleContext context) throws Exception {
System.out.println("started");
http = new HttpServiceTracker(context);
http.open();
started=true;
}
public void stop(BundleContext context) throws Exception {
System.out.println("stopped");
started=false;
http.close();
}
public static boolean isStarted(){
return started;
}
private class HttpServiceTracker extends ServiceTracker {
public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
}
public Object addingService(ServiceReference reference) {
HttpService httpService = (HttpService) context.getService(reference);
try {
httpService.registerResources("/home", "/home.html", null);
httpService.registerServlet("/servlet", new DServlet(context), null, null);
}
catch (Exception e) {
e.printStackTrace();
}
return httpService;
}
public void removedService(ServiceReference reference, Object service) {
HttpService httpService = (HttpService) service;
httpService.unregister("/servlet"); //$NON-NLS-1$
httpService.unregister("/home");
super.removedService(reference, service);
}
}
}
edit: my purpose is to retrieve the bundlecontext and getting information about bundles to visualize them in the applet.
First your browser downloads the html file. After it is downloaded, the browser checks the applet tag in the html. It starts a JVM that tries to download the applet from the url:
http://localhost:8080/bridge/thesis.bot.wab.applet.DApplet.class
However, nothing is there and why would be anything?
You should register the class file or the full jar file as a resource. After that, you should insert an applet tag into the html file that points to the jar or class file. In case your applet has any dependencies, those jars should be listed as well.
It is useful to switch on the Java console (google for it) and push the button "5" to have low level debug messages. There you will see the issues why your applet does not start (downloading urls, dependency issues...)

My custom css are not getting picked up completely

I have created a custom css for tree and other widgets.
I have made the following entry
<inherits name='com.google.gwt.user.theme.standard.Standard' />
<stylesheet src="CustomStylesheet.css" />
But still only some of the styles are getting picked up and others don't. Has anyone faced a similar problem?
It will be either one of the below,
Either you have to use CSS Resource as mentioned by Andrew or you have missed Doctype declaration.
You can also visit this link: doctype explantion w.r.t to GWT
you should write the same style classnames with "com/google/gwt/user/cellview/client/CellTree.css" css file and you may change content css
pulic class MyClass extends Composite {
public interface MyResources extends CellTree.Resources {
#ImageResource.ImageOptions(flipRtl = true)
#Source("cellTreeClosedItem.gif")
ImageResource cellTreeClosedItem();
#ImageResource.ImageOptions(flipRtl = true)
#Source("cellTreeOpenItem.gif")
ImageResource cellTreeOpenItem();
#Override
#Source({"com/google/gwt/user/cellview/client/CellTree.css"})
CellTree.Style cellTreeStyle();
}
private MyResources res = GWT.create(MyResources.class);
public void onInitialize(){
cellTree = new CellTree(treeViewModel, null, res);
}
}

Why does GWT Designer with UiBinder mess up this simple dialog?

I'm using Eclipse 3.7, GWT 2.5, Java 1.6, and the latest GPE. I've used UiBinder quite a bit, and now we're looking into using GWT Designer for the next version of our app. I created a basic web app project and let it generate its sample code. Then did New->GWT Designer->GWT UiBinder->Dialog Box. Then I added a button to spawn the popup, and a size and title for the dialog. Here's the widget code:
public class TestPopup extends DialogBox {
private static final Binder binder = GWT.create(Binder.class);
#UiField FlowPanel flowPanel;
interface Binder extends UiBinder<Widget, TestPopup> {
}
public TestPopup() {
setWidget(binder.createAndBindUi(this));
setTitle("Test Popup Title");
setPixelSize(400, 300);
}
}
and the corresponding *ui.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<ui:style>
.panel {
padding: 5px;
border: 5px solid cornflowerblue;
background-color: Menu;
}
</ui:style>
<g:FlowPanel styleName="{style.panel}" ui:field="flowPanel" width="100%" height="100%"/>
</ui:UiBinder>
and this is the result. Can anyone explain how these tools can hack a simple configuration into this:
This is a known issue. The DecoratorPanel and DecoratedPopupPanel Widgets have problems like this when you attempt to set their size specifically. Don't specify the size of the DialogBox. Instead, specify the size of the DialogBox's child Widget and the DialogBox should match it fine.

Uibinder Widgets

Is it possible to reuse widgets defined on Uibinder
example:
<g:SuggestBox ui:field='searchBox' />
I mean using the same SuggestBox in two different places.
if it is possible how can I do the call or what ever ?
Thanks for help.
You can do that, here is an example:
Define a widget you want to reuse:
ExampleLabel.java:
package com.example.client;
import import com.google.gwt.user.client.ui.Label;
public class ExampleLabel extends Composite {
interface ExampleLabelBinder extends UiBinder<Widget, ExampleLabel>{}
private static ExampleLabelBinder binder=GWT.create(ExampleLabelBinder.class);
public ExampleLabel() {
initWidget(binder.createAndBindUi(this);
}
}
ExampleLabel.ui.xml
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:Label>Just some text</g:Label>
</ui:UiBinder>
To use it you do something like this:
UseExampleLabel.ui.xml:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:myWidgets='urn:import:com.example.client>
<g:FlowPanel>
<myWidgets:ExampleLabel></myWidgets:ExampleLabel>
<myWidgets:ExampleLabel></myWidgets:ExampleLabel>
<myWidgets:ExampleLabel></myWidgets:ExampleLabel>
</g:FlowPanel>
</ui:UiBinder>
The third line points to the package your widgets is in you want to reuse.