【问题标题】:Why does eclipse GWT designer for uibinder generate exception because of uifield为什么 Eclipse GWT Designer for uibinder 会因为 uifield 而产生异常
【发布时间】:2013-10-15 22:39:06
【问题描述】:

我是 GWT 应用程序开发的新手,所以学习曲线还没有真正理顺;但是,在我看来,以下内容应该不会造成问题。

我正在使用网络上的示例代码来了解更多信息。我正在使用 Eclipse Kepler 和 GWT 设计器 3.1.2。

该应用程序正常工作,但在 Login.ui.xml 中的样式引用中减去了一个小错误,我已修复该错误,但试图找出我是如何破坏它的。

在 Login.ui.xml 上使用设计模式时出现以下错误。

Unable to create @UiField(provided=true).
You are attempting to use @UiField(provided=true) for (com.learn.client.LoginResources) res, however GWT Designer was not able to create instance of requested object. This can be caused by one of the following reasons: 

Type is interface and you've not provided *.wbp-component.xml description with UiBinder.createInstance script. 
GWT Designer attempted to use shortest constructor of type (such as default constructor), but it caused exception. 


Show stack trace. 
Hide stack trace. 

Stack trace:
org.eclipse.wb.internal.core.utils.exception.DesignerException: 4508 (Unable to create @UiField(provided=true).). com.learn.client.LoginResources res
    at com.google.gdt.eclipse.designer.uibinder.parser.UiBinderParser.createProvidedField(UiBinderParser.java:291)
    at com.google.gdt.eclipse.designer.uibinder.parser.UiBinderParser$2.invoke(UiBinderParser.java:182)
    at com.sun.proxy.$Proxy670.provideField(Unknown Source)

我的来源如下:

Login.ui.xml
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:gwt="urn:import:com.google.gwt.user.client.ui"
    xmlns:res="urn:with:com.learn.client.LoginResources">
    <ui:with field="res" type="com.learn.client.LoginResources" />
   <gwt:HTMLPanel>
      <div align="center">
         <gwt:VerticalPanel res:styleName="style.background">
            <gwt:Label text="Login" res:styleName="style.blackText" />
            <gwt:TextBox ui:field="loginBox" res:styleName="style.box" />
            <gwt:Label text="Password" res:styleName="style.blackText" />
            <gwt:PasswordTextBox ui:field="passwordBox"  res:styleName="style.box" />
            <gwt:HorizontalPanel verticalAlignment="middle">
               <gwt:Button ui:field="buttonSubmit" text="Submit" res:styleName="style.loginButton" />
               <gwt:CheckBox ui:field="myCheckBox" />
               <gwt:Label ui:field="myLabel" text="Remember me" res:styleName="style.blackText" />
            </gwt:HorizontalPanel>
            <gwt:Label ui:field="completionLabel1" res:styleName="style.blackText" />
            <gwt:Label ui:field="completionLabel2" res:styleName="style.blackText" />
         </gwt:VerticalPanel>
      </div>
   </gwt:HTMLPanel>
</ui:UiBinder> 

Login.java
public class Login extends Composite {
       private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class);
       private Boolean tooShort = false;

       @UiField(provided=true) TextBox loginBox;
       @UiField TextBox passwordBox;
       @UiField Label completionLabel1;
       @UiField Label completionLabel2;
       @UiField(provided=true) final LoginResources res;

       /*
       * @UiTemplate is not mandatory but allows multiple XML templates
       * to be used for the same widget. 
       * Default file loaded will be <class-name>.ui.xml
       */
       @UiTemplate("Login.ui.xml")
        interface LoginUiBinder extends UiBinder<Widget, Login> {
       }

       public Login() {
           loginBox = new TextBox();
          this.res = GWT.create(LoginResources.class);
          res.style().ensureInjected();
          initWidget(uiBinder.createAndBindUi(this));
       }
        :
        :
        Handlers
        :
        :
    }

nResources.java
public interface LoginResources extends ClientBundle {
       /**
       * Sample CssResource.
       */
       public interface MyCss extends CssResource {
          String blackText();

          String redText();

          String loginButton();

          String box();

          String background();
       }

       @Source("LoginStyle.css")
       MyCss style();
}

LoginStyle.css
.blackText {
   font-family: Arial, Sans-serif;
   color: #000000;
   font-size: 11px;
   text-align: left;
}

.redText {
   font-family: Arial, Sans-serif;
   color: #ff0000;
   font-size: 11px;
   text-align: left;
}

.loginButton {
   border: 1px solid #3399DD;
   color: #FFFFFF;
   background: #555555;
   font-size: 11px;
   font-weight: bold;
   margin: 0 5px 0 0;
   padding: 4px 10px 5px;
   text-shadow: 0 -1px 0 #3399DD;
}

.box {
   border: 1px solid #AACCEE;
   display: block;
   font-size: 12px;
   margin: 0 0 5px;
   padding: 3px;
   width: 203px;
}

.background {
   background-color: #999999;
   border: 1px none transparent;
   color: #000000;
   font-size: 11px;
   margin-left: -8px;
   margin-top: 5px;
   padding: 6px;
}

【问题讨论】:

    标签: eclipse gwt web-applications uibinder google-eclipse-plugin


    【解决方案1】:

    似乎设计师在需要生成器时不支持提供的字段。

    我会在 Login.ui.xml 中包含 LoginStyle.css 的内容

    类似这样的:

    <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
        xmlns:g='urn:import:com.google.gwt.user.client.ui'> 
        <ui:style>
              .container {
              }
            </ui:style>
        <g:FlowPanel ui:field="container" addStyleNames="{style.container}">
        </g:FlowPanel>
    </ui:UiBinder>
    

    【讨论】:

    • 我想过这样做;但是,我找不到可以正常工作的示例。此外,当我在 GWT 文档中读到该方法已被贬值时,我放弃了这种追求。你有任何有效的方法的例子吗?我在我的 Login.ui.xml 中尝试了以下内容。 ,css与ui.xml在同一文件夹中
    • 抱歉,我在上一条评论中错过了作为 ui:style 一部分的字段名称。这是我使用您推荐的代码片段。它也不起作用......
      ​​
    • 编辑了我的回复。顺便说一句,我不太信任设计师,创建初始屏幕是可以的,但是一旦开发进展顺利,并且您在类中引入更多代码,您可能会遇到问题。
    • 我想我关注的高级代码可能会产生更多问题。 WYSIWYG 只能让你走这么远,然后橡胶遇见道路,你已经开始编程。我在您的建议中发现的问题是,将样式代码直接放在 ui.xml 中等于规避了 css 文件的目的和优势。我想我会使用我原来的解决方案,并简单地接受 gui 编辑工具将不再有用。应用程序的最终输出一切正常,我只能使用 gui 工具。还是谢谢。
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签