问题描述
如果我能做到这一点,我如何在Wicket的JavaScript代码中调用Java代码(例如方法)。
If I can do this, how do I call Java code (methods for instance) from within JavaScript code, in Wicket.
推荐答案
erk。正确的答案是ajax回拨。您可以手动编写js以挂接到wicket js,也可以从java中的wicket组件设置回调。
例如,来自AjaxLazyLoadPanel:
erk. The correct answer would be ajax call backs. You can either manually code the js to hook into the wicket js, or you can setup the callbacks from wicket components in java.For example, from AjaxLazyLoadPanel:
component.add( new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
// your code here
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead( response );
response.renderOnDomReadyJavascript( getCallbackScript().toString() );
}
}
此示例显示如何将回调代码添加到Wicket中的任何组件。在浏览器中触发OnDomReady事件后,加载页面时,Wicket会引起它的js enging,使用Ajax回调你的代码到上面显示的'response'方法,此时你可以在服务器上执行Java代码,并可能将组件添加到ajax目标中-bdered。
This example shows how to add call back code to any Component in Wicket. After the OnDomReady event fires in your browser, when loading a page, Wicket will cause it's js enging, to call back into your code, using Ajax, to the 'respond' method shown above, at which point you can execute Java code on the server, and potentially add components to the ajax target to be re-rendered.
从js手动完成,你可以通过将getCallbackScript()。toString()打印到wicket组件上的属性来挂钩到wicket的系统,然后你可以从js访问它。从wicket的wicketAjaxGet手动调用来自js的这个url来自wicket-ajax.js。
To do it manually, from js, you can hook into wicket's system by printing out getCallbackScript().toString() to a attribute on a wicket component, which you'll then be able to access from js. Calling this url from js manually with wicket's wicketAjaxGet from wicket-ajax.js.
查看关于此主题的很多对话的邮件列表:
Check out the mailing list for lot's of conversation on this topic:http://www.nabble.com/Wicket-and-javascript-ts24336438.html#a24336438
这篇关于如何从Wicket中的JavaScript代码调用Java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!