使用 Wicket ,
如何将var slideCounter
发送给Wicket?
有人能提供一个例子吗?
我无法找到更多相关信息。
$(document).on('click', '.lean-overlay', function() {
var slideCounter = 0;
// TODO Send slidecounter to wicket
});
答案 0 :(得分:3)
发送请求非常简单:Wicket.Ajax.post({"u": "the/url?slideCounter="+slideCounter})
更复杂的部分是构建the/url
。
requestCycle.urlFor(component)
#getCallbackUrl()
获得网址后,您需要将其存储在网页DOM中,例如使用OnDomReadyHeaderItem.forScript(" window.TheUrl ='" + theUrl +"&#39 ;;")
答案 1 :(得分:2)
您可以使用ajax回拨从javascript调用wicket代码。你可以这样做:
JAVA CODE:
AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
@Override
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
String componentMarkupId = component.getMarkupId();
String callbackUrl = getCallbackUrl().toString();
response.render(JavaScriptHeaderItem.forScript(
"var componentMarkupId='" + componentMarkupId
+ "'; var callbackUrl='" + callbackUrl + "';",
"values"));
}
protected void respond(final AjaxRequestTarget target) {
IRequestParameters parameters = RequestCycle.get().getRequest()
.getQueryParameters();
// write yout java code here
// if you want to use the slideCounter variable
// you have to retrieve its value like this:
// parameters.getParameterValue("slideCounter").toString()
}
};
add(behave);
JAVASCRIPT CODE:
$(document).on('click', '.lean-overlay', function() {
var slideCounter = 0;
executeJava(slideCounter);
});
function executeJava(slideCounter) {
try {
var commandToSend = 'slideCounter=' + slideCounter;
var wcall = Wicket.Ajax.post({
u: callbackUrl + '&' + commandToSend
});
} catch (e) {
alert(e);
}
}