3

我准备了一个可重复使用的面板并将其添加到我的页面中。我的页面表单中有 2 个下拉选项。我使用来自https://cwiki.apache.org/WICKET/dropdownchoice-examples.html#DropDownChoiceExamples的 ajax 示例 - 注意两个 DDC 工作正常(更改一个值然后隐藏/取消隐藏另一个。但它不适用于我面板。我正在使用:

private final MyPanel panel1 = new MyPanel ("MyPanel"); 
panel1.setOutputMarkupPlaceholderTag(true); 

...在 DDC1 ajax 行为方法中:

onUpdate(AjaxRequestTarget target) { ...
    DDC2.setVisible(true); 
    panel1.setVisible(true); 
}

我必须提交表单以隐藏/取消隐藏panel1。如何使其以与DDC2不提交表单相同的方式工作?

4

1 回答 1

6

你需要 :

panel1.setOutputMarkupId(true); 

panel1.setOutputMarkupPlaceholderTag(true);

实际上,Ajax 工作并不总是需要你所拥有的,但是从客户端进行刷新驱动时需要它。据我所知,它不会伤害任何东西......

在行为中,您需要告诉目标刷新它:

onUpdate(AjaxRequestTarget target) { ...
    DDC2.setVisible(true); 
    panel1.setVisible(true);
    target.addComponent(DDC2);
    target.addComponent(panel1); 
}
于 2012-10-24T15:31:28.493 回答