wicket:如何使用ajax更新表单组件,而不是整个表单



我有一个wicket下拉选项,当我选择一些东西时,我想更新表单中的一些组件。使用wicket(1.4)ajax可以很好地工作。然而,它正在更新整个表单,包括下拉选项本身。下拉列表中有很多项目(可能是2000个),所以从性能的角度来看,这并不好。

以下是页面层次结构:

form (Form)
|----packageDDC (DropDownChoice)
|----pptview (RefreshingView)
|----buy (Button)
packageDDC.add(new AjaxFormComponentUpdatingBehavior("onchange") {
protected void onUpdate(AjaxRequestTarget target) {
//--snip-- update pricepoints which back up the pptview
target.addComponent(form);  //ie the form
}
}

在ajax调试窗口中,我可以看到每次都会重新发送所有下拉选择选项

我想做的只是通过ajax更新pptview和Button,而不是dropdownchoice的内容。

我尝试将pptview添加到目标,但它抱怨RefreshgViews无法通过ajax更新。我试着用EnclosureContainer包装pptview,但wicket也不喜欢(关于setRenderBodyOnly)因此,我尝试使用WebMarkupContainer(名为"pptcontainer"),并将pptview设置为其子级,但现在pptvview没有更新。相反,它说(在Ajax调试中):

"ERROR: Wicket.Ajax.Call.processComponent: Component with id [[purchaseButton2f]] was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update."
"ERROR: Wicket.Ajax.Call.processComponent: Component with id [[pptcontainer2e]] was not found while trying to perform markup update. Make sure you called component.setOutputMarkupId(true) on the component whose markup you are trying to update."

这些物体肯定有这样的设置:

buy.setOutputMarkupId(true);
pptcontainer.setOutputMarkupId(true);
pptcontainer.setOutputMarkupPlaceholderTag(true);

因此页面没有正确更新。

我做错了什么?

新的层次结构是:

form (Form)
|----packageDDC (DropDownChoice)
|----pptcontainer (WebMarkupContainer)
|      |----pptview (RefreshingView)
|----buy (Button)

我在弹出窗口中遇到了同样的问题,该窗口的内容由ajax调用提供。在我的案例中,通过将html占位符"wicket:container"更改为本文中提出的"div"元素,解决了这个问题:http://sha.nnoncarey.com/blog/archives/36

在这个更改之后,生成的html具有正确的id,wicket没有问题找到它并用AJAX响应替换内容。

最新更新