如何在 GWT UiBinder 中引用 Widget?
How to reference a Widget in GWT UiBinder?
是否可以引用 UiBinder 创建的小部件并将其传递给 *.ui.xml 文件中其他小部件的 setter?
我已尝试使用以下代码创建一个标签 (CustomLabel
),该标签 (CustomLabel
) 可以监听并跟踪表单小部件 (CustomWidget
) 的状态。问题是 GWT 编译失败:
[ERROR] Exception in thread "main" java.lang.WhosebugError
[ERROR] at sun.nio.cs.UTF_8$Encoder.encodeLoop(UTF_8.java:691)
[ERROR] at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:579)
[ERROR] at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:271)
[ERROR] at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
[ERROR] at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
[ERROR] at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
[ERROR] at java.io.BufferedWriter.flush(BufferedWriter.java:253)
[ERROR] at java.io.PrintWriter.newLine(PrintWriter.java:482)
[ERROR] at java.io.PrintWriter.println(PrintWriter.java:629)
[ERROR] at java.io.PrintWriter.println(PrintWriter.java:740)
[ERROR] at com.google.gwt.dev.util.log.PrintWriterTreeLogger.doLog(PrintWriterTreeLogger.java:79)
[ERROR] at com.google.gwt.dev.util.log.PrintWriterTreeLogger.doCommitBranch(PrintWriterTreeLogger.java:65)
[ERROR] at com.google.gwt.dev.util.log.AbstractTreeLogger.commitMyBranchEntryInMyParentLogger(AbstractTreeLogger.java:256)
[ERROR] at com.google.gwt.dev.util.log.AbstractTreeLogger.branch(AbstractTreeLogger.java:167)
[ERROR] at com.google.gwt.core.ext.TreeLogger.branch(TreeLogger.java:212)
[ERROR] at com.google.gwt.editor.rebind.model.EditorModel.createEditorData(EditorModel.java:381)
[ERROR] at com.google.gwt.editor.rebind.model.EditorModel.createEditorData(EditorModel.java:390)
[ERROR] at com.google.gwt.editor.rebind.model.EditorModel.createEditorData(EditorModel.java:390)
查看。ui.xml:
<g:HTMLPanel>
<x:CustomLabel forTarget={widget} />
<x:CustomWidget ui:field="widget" />
</g:HTMLPanel>
View.java:
@UiField
CustomWidget widget;
CustomLabel.java:
public void setForTarged(CustomWidget forTarget) {
this.forTarget = forTarget
}
原则上这应该可行。我在我的代码中使用了类似的引用。
在你的View.java中:
@UiField
CustomWidget customWidget;
应该是
@UiField
CustomWidget widget;
不,您不能这样做 - 当您的 setForTarget
方法被 UiBinder 调用时,还没有小部件可用。
您可以在您的代码中调用此方法在您的自定义小部件已初始化之后。
是否可以引用 UiBinder 创建的小部件并将其传递给 *.ui.xml 文件中其他小部件的 setter?
我已尝试使用以下代码创建一个标签 (CustomLabel
),该标签 (CustomLabel
) 可以监听并跟踪表单小部件 (CustomWidget
) 的状态。问题是 GWT 编译失败:
[ERROR] Exception in thread "main" java.lang.WhosebugError
[ERROR] at sun.nio.cs.UTF_8$Encoder.encodeLoop(UTF_8.java:691)
[ERROR] at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:579)
[ERROR] at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:271)
[ERROR] at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
[ERROR] at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
[ERROR] at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
[ERROR] at java.io.BufferedWriter.flush(BufferedWriter.java:253)
[ERROR] at java.io.PrintWriter.newLine(PrintWriter.java:482)
[ERROR] at java.io.PrintWriter.println(PrintWriter.java:629)
[ERROR] at java.io.PrintWriter.println(PrintWriter.java:740)
[ERROR] at com.google.gwt.dev.util.log.PrintWriterTreeLogger.doLog(PrintWriterTreeLogger.java:79)
[ERROR] at com.google.gwt.dev.util.log.PrintWriterTreeLogger.doCommitBranch(PrintWriterTreeLogger.java:65)
[ERROR] at com.google.gwt.dev.util.log.AbstractTreeLogger.commitMyBranchEntryInMyParentLogger(AbstractTreeLogger.java:256)
[ERROR] at com.google.gwt.dev.util.log.AbstractTreeLogger.branch(AbstractTreeLogger.java:167)
[ERROR] at com.google.gwt.core.ext.TreeLogger.branch(TreeLogger.java:212)
[ERROR] at com.google.gwt.editor.rebind.model.EditorModel.createEditorData(EditorModel.java:381)
[ERROR] at com.google.gwt.editor.rebind.model.EditorModel.createEditorData(EditorModel.java:390)
[ERROR] at com.google.gwt.editor.rebind.model.EditorModel.createEditorData(EditorModel.java:390)
查看。ui.xml:
<g:HTMLPanel>
<x:CustomLabel forTarget={widget} />
<x:CustomWidget ui:field="widget" />
</g:HTMLPanel>
View.java:
@UiField
CustomWidget widget;
CustomLabel.java:
public void setForTarged(CustomWidget forTarget) {
this.forTarget = forTarget
}
原则上这应该可行。我在我的代码中使用了类似的引用。
在你的View.java中:
@UiField
CustomWidget customWidget;
应该是
@UiField
CustomWidget widget;
不,您不能这样做 - 当您的 setForTarget
方法被 UiBinder 调用时,还没有小部件可用。
您可以在您的代码中调用此方法在您的自定义小部件已初始化之后。