以下代码用于将属性样式设置为 body 元素并向其注册剪切/粘贴代码,但失败。奇怪的是,在调试的时候,变量body
不为空,并且属性“style”存在,但框架没有这个孩子。运行工作没有按预期工作,调用时 NPE 被抛出setBodyContent()
。
public class TextAreaExt extends RichTextArea
{
private BodyElement body;
@Override
protected void onLoad()
{
super.onLoad();
body = ((FrameElement) getElement().cast())
.getContentDocument().getBody();
body.setAttribute("style", "color:gray;");
registerOnCut(body);
}
public void setBodyContent(String text)
{
body.setInnerText(text);
}
private native void registerOnCut(BodyElement element) /*-{
var that = this;
console.log("registerOnCut");
element.oncut = $entry(function(event) {
//invoke method to adjust height based on content
return false;
});
element.onpaste = $entry(function(event) {
//invoke method to adjust height based on content
return false;
});
}-*/;
}