在 MyPanel.ui.xml 中:
<button class="btn" ui:field="myButton">Save</button>
在 MyPanel.java 中:
public class MyPanel extends Composite {
...
@UiField ButtonElement myButtonUi;
...
public MyScreen() {
final HTMLPanel panel = uiBinder.createAndBindUi(this);
initWidget(panel);
Button myButton = Button.wrap(myButtonUi);
在 MyEntryPoint.java 中:
if (....)
RootPanel.get().add(new MyPanel());
所以我想我不太了解如何使用 UiBinder。
我打算将 HTML 与 ui:field=".." 一起使用,以便网页设计师可以在 UI 字段上设置 class="xx" 之类的内容。大多数 GWT 文档都假定您有一个 Button 而不是 ButtonElement。但是如果我使用 Button 我需要<g:Button>
在 HTML 文档中有一个,这意味着我的网页设计师不能设置类?我的意思是 UiBinder 的目的是允许人们使用普通的 HTML 并将其与 GWT 代码集成?
当我执行上述操作时,在换行线上,我在开发模式下从以下位置获得 NullPointerException:
public static Button wrap(com.google.gwt.dom.client.Element element) {
// Assert that the element is attached.
assert Document.get().getBody().isOrHasChild(element);
在生产模式下,它似乎工作正常。在 Eclipse 的开发模式调试器中,当我右键单击并“检查”表达式“Document.get().getBody()”时,Eclipse 显示“无法向非类类型对象发送静态消息”。
我应该怎么办?是否因为我需要先附加元素而发生空指针异常?如果是这样,怎么做?(我已经在调用 createAndBindUi 并且传递给 wrap 的元素是非空的)。