gpt4 book ai didi

java - Wicket 组件不会通过 AJAX 刷新

转载 作者:行者123 更新时间:2023-12-01 10:11:09 27 4
gpt4 key购买 nike

我有一个 Wicket 页面,其中包含一些应通过 AJAX 更新的组件。我有以下 AjaxBehavior:

private class MyAjaxBehavior extends AbstractDefaultAjaxBehavior {

@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.renderOnLoadJavascript("wicketAjaxPost(\"" + getCallbackUrl() + "\")");
}

@Override
public void onConfigure(Component component) {
firstComponent.setOutputMarkupId(true);
secondComponent.setOutputMarkupId(true);
}

@Override
protected void respond(AjaxRequestTarget target) {
firstComponent.replaceWith(createFirstComponent());
target.addComponent(firstComponent);

secondComponent.replaceWith(createSecondComponent());
target.addComponent(secondComponent);
}
}

我有一个像这样的组件层次结构:

Page
- fragment1
- fragment1-1
- firstComponent
- secondComponent

问题是 firstComponent 在 AJAX 回调后从未刷新。 secondComponent 已正确更新。我尝试将 firstComponent 移动到 frament1-1 (只是实验),它成功了!我尝试使用一些额外的片段来包装 firstComponent 但没有帮助。

我尝试调试 Wicket 的 AjaxRequestTarget.respondComponent()。有如下代码:

        // Initialize temporary variables
final Page page = component.findParent(Page.class);
if (page == null)
{
// dont throw an exception but just ignore this component, somehow
// it got
// removed from the page.
// throw new IllegalStateException(
// "Ajax request attempted on a component that is not associated
// with a Page");
LOG.debug("component: " + component + " with markupid: " + markupId +
" not rendered because it was already removed from page");
return;
}
对于 firstComponentsecondComponent 来说,

page 在这里都是 null,但第二个组件以某种方式重新渲染。

有什么想法为什么 firstComponent 没有重新渲染吗?我应该在哪里挖?我使用 Wicket 1.4.22。

UPD

我尝试将新组件添加到target,而不是旧组件。它在页面上创建新组件,但不会刷新旧组件。所以我的页面上有两个组件,而不是一个。它还由于某种原因破坏了 HTML 标记结构。像这样:

<div>
<div id="generated">new component is added here</div>
<table>
...
<tr>old component</tr>
</table>
</div>

我的 firstComponent 的 wicket 标记如下所示:

<div>
<table class="summary" style="width: 100%">
<tr>
<div wicket:id="firstComponent" />
</tr>
</table>
</div>

...

<wicket:fragment wicket:id="firstComponentFragment">
<th>title</th>
<td><span wicket:id="someText"></span></td>
</wicket:fragment>

因此您可以看到新组件已添加到表格外部。

最佳答案

有时,将父组件(例如表单本身)添加到 ajax 响应目标会更容易,这样您就可以确保其下面的所有内容都已更新。因此没有重复或丢失更新。仅当您需要这种情况下的性能时才需要更新特殊组件。即使您可以定义一个包装容器,您也可以更新它以确保旧标记被删除。

关于java - Wicket 组件不会通过 AJAX 刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36105966/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com