我正在尝试使XEditable Jquery-ui 插件与 GWT/Errai 一起使用。但是,当单击所谓的“ x-editable ”字段时,什么也没有发生。我的代码可能有什么问题:
这是我的代码:
爪哇:
@Dependent
@Page
@Templated
public class XeditableTest extends Composite {
@DataField
private Element xfield;
@PostConstruct
public void setup() {
xeditable(xfield);
}
public static native void xeditable(Element el) /*-{
$wnd.alert($wnd.$(el).length);
$wnd.$(function(){
$wnd.$.fn.editable.defaults.mode = 'inline';
$wnd.$(el).editable({
validate: function(value) {
if($wnd.$.trim(value) == '') return 'This field is required';
}
});
}
)
}-*/;
@EventHandler("xfield")
public void onAnchorClicked(ClickEvent clickEvent) {
clickEvent.preventDefault();
}
}
模板:
<div class="control-group">
<a href="#" data-field="xfield" id="firstname" data-type="text" data-pk="1" data-placement="right" data-placeholder="Required" data-original-title="Enter your firstname" class="editable editable-click editable-empty">Empty</a>
</div>
更新:
将 Element 传递给xeditable
方法后出现错误:
ERROR] Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot read property 'defaults' of undefined
[ERROR] at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
[ERROR] at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
[ERROR] at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
[ERROR] at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
[ERROR] at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
[ERROR] at com.myapp.client.local.XeditableTest.xeditable(XeditableTest.java)
[ERROR] at com.myapp.client.local.XeditableTest.setup(XeditableTest.java:53)