2014-02-20 80 views
0

我有一个检票下拉选项,当我选择某个内容时,我想更新表单中的某些组件。这是使用wicket(1.4)ajax正常工作。但是,它正在更新整个表单,包括下拉选项本身。下拉列表中有相当多的项目(可能是2000),因此从性能角度来看并不是很好。wicket:如何使用ajax更新表单组件,而不是整个表单

这里的页面层次结构:

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调试窗口,我可以看到所有的下拉菜单中选择选项被重新发送,每次

我想要做的就是只更新pptview和通过ajax的按钮,而不是下拉选项的内容。

我试着将pptview添加到目标,但它抱怨RefreshgViews无法通过ajax更新。 我试图用EnclosureContainer包装pptview,但是wicket不喜欢那样(关于setRenderBodyOnly) 因此我尝试使用WebMarkupContainer(称为'pptcontainer')并将pptview设置为该子项 - 但现在pptview没有更新。相反,它说(在阿贾克斯调试):

"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." 

以及这些对象肯定是有这个设置为true:

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

因此,网页无法正确更新。

我在做什么错?

新的层次是:

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

你在正确的轨道上。不知道为什么找不到pptcontainer2e。查看页面源代码(或使用Firebug)并检查pptcontainer的html元素。它有一个id属性吗?它是否与Wicket ajax错误消息的id属性相匹配? – bernie

+0

我得到了你想要做的事情,并且看不清究竟发生了什么。不过,我还希望将下拉列表更改为更具动态性的内容(Select2),以便无论如何都不需要检索所有2000值。 – RobAu

回答

3

我面临同样的问题,与内容是通过Ajax调用提供的弹出窗口。在我的情况下,问题是通过更改本文建议的html占位符“wicket:container”为“div”元素来解决的:http://sha.nnoncarey.com/blog/archives/36

在此更改生成的html有正确的id并且wicket没有问题找到它并且用AJAX响应替换内容。

相关问题