[英]Wicket Strange behaviour of URL with ajax
我有一些奇怪的步驟。 我在Head渲染階段渲染了ajax行為
final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
protected void respond(final AjaxRequestTarget target) {
boolean undoEn = getRequest().getQueryParameters().getParameterValue("undoEn").toBoolean();
if (undoEn) {
mSaveButton.setEnabled(true);
target.add(mSaveButton);
}
}
};
public String getCallbackName() {
return "saveButtonVisibilityToggle";
}
@Override
public void renderHead(IHeaderResponse response) {
String script = getCallbackName() + " = function (e) { Wicket.Ajax.ajax({\"u\": \"" + behave.getCallbackUrl() + " + &undoEn=\"+e+\"\" });}";
response.render(OnDomReadyHeaderItem.forScript(script));
}
一切都運行良好,每次在tinyMCE編輯器中更改節點時都會調用此行為
settings.addCustomSetting(" setup: function(editor) {" +
" editor.on('NodeChange', function(e) {" +
" editor.save();" +
getCallbackName() + "(editor.undoManager.hasUndo())" +
" });" +
" }");
但有時當我離開瀏覽器標簽時,更改幾個標簽(chrome)然后使用其他應用程序幾分鍾,然后轉回我們的標簽,ajax url意外地出現在瀏覽器網址中。
http://localhost:8080/wicket/bookmarkable/com.tac.kulik.pages.SomePage?3-1.IBehaviorListener.0-contentPanel&entityId=2+++&undoEn=true
這也很奇怪,相反,normap參數傳遞了它添加的+++符號
順便說一句,這種嘆息被認為是“2”,所以出於某種原因“+”變成了空白
更新1使用@svenmeier回答我的頁面啟動無限循環刷新。 與日志
org.apache.wicket.core.request.mapper.StalePageException: A request to
page '[Page class = x.x.x.CardPage, id = 25, render count = 1]' has been
made with stale 'renderCount'. The page will be re-rendered.
並且由於某種原因,表現為鏈接有renderCount 1,但表單有0.來自瀏覽器的請求jquery-1.12.4-ver-1476216952000.js:10254 XHR完成加載:GET“ http:// localhost:8080 / wicket / bookmarkable /com.tac.pages.ca ...?4-0.IBehaviorListener.0-contentPanel&cardId = 1&_ = 1476873175645&undoEn = true“
我添加了一些JS以防止cicling刷新,但我仍然有Stale例外
"if (editor.undoManager.hasUndo()) { " +
" console.debug('Behave called ');" +
behave.getCallbackScript() +
" }" +
這是我的舉止
final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
protected void respond(final AjaxRequestTarget target) {
log.info("Behave called");
boolean undoEn = getRequest().getQueryParameters().getParameterValue("undoEn").toBoolean();
if (undoEn) {
mSaveButton.setEnabled(true);
target.add(mSaveButton);
}
}
//
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
String undoEn = "return {'undoEn': editor.undoManager.hasUndo()};";
attributes.getDynamicExtraParameters().add(undoEn);
}
};
並沒有區別,它可以表現得沒有任何實現,頁面行為相同((
final AbstractDefaultAjaxBehavior behave = new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
}
};
您應該重新設計行為以使用動態額外參數。
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
super.updateAjaxAttributes(attributes);
String undoEn = "return {'undoEn': editor.undoManager.hasUndo()}";
attributes.getDynamicExtraParameters().add(undoEn);
}
和:
settings.addCustomSetting(
"setup: function(editor) {" +
" editor.on('NodeChange', function(e) {" +
" editor.save();" +
" " + getCallbackScript() + ";" +
" });" +
"}");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.