使用uibinder延迟绑定失败GWT [英] Deferred binding failed GWT using uibinder

查看:112
本文介绍了使用uibinder延迟绑定失败GWT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是项目中使用的全部文件。它给出这些错误



pre $ [错误] [cricketscore] - 延迟绑定失败'test.client.UserDashboard.MyUiBinder';预计后续失败

  [错误] [cricketscore]  - 无法加载模块入口点类test.client.DashBoard(有关详细信息,请参阅关联的异常)。 

请帮我解决问题。



Cricketscore.gwt.xml

 <?xml version =1.0encoding =UTF-8?> ; 
<! -
更新您的GWT版本时,您还应该更新此DTD参考
,以便您的应用程序可以利用最新的GWT模块功能。
- >
<!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'>
<! - 继承核心Web Toolkit的东西。 - >
<继承了name ='com.google.gwt.user.User'/>

<! - 继承默认的GWT样式表。您可以更改 - >
<! - 通过取消注释,您的GWT应用程序的主题 - >
<! - - 以下任何一行。 - >
<继承了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'/> - >

<! - 其他模块继承 - >

<! - 指定应用程序入口点类。 - >
< entry-point class ='test.client.DashBoard'/>

<! - 指定可翻译代码的路径 - >
< 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实现EntryPoint {
$ b $ @覆盖
public void onModuleLoad(){
RootPanel.get()。add(new UserDashboard() );


$ / code $ / pre
$ b $ 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自动生成的构造函数存根
}
}

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;
$ b $ public class UserDashboard extends Composite {
interface MyUiBinder扩展了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(){
返回新的CricketScores(teamNames);



$ div $解析方案

你在您的代码中有冲突信息:a @UiConstructor @UiFactory 实际上,有一个优先顺序,但它可能会让开发者感到困惑,比如你)。
$ b UiBinder会更喜欢 @UiFactory

code>超过 @UiConstructor ,而你的工厂没有参数,所以你的XML中的 teamNames 属性暂时映射到 setTeamNames setter,它不存在,因此Class CricketScores没有合适的setTeamNames()方法错误。 / p>

这个问题在你的代码中是概念性的:你的 UserDashboard 是用一个团队名称列表构造的, CricketScores 窗口小部件,因此窗口小部件在XML中不应该有 teamNames 属性。


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.

这篇关于使用uibinder延迟绑定失败GWT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆