带下拉选择的检票口调色板
我创建了一个包含值的调色板,并使用 AjaxFormComponentUpdatingBehavior 创建了一个 DropDownChoice ddcdomaines 来更新选择列表,但我不知道该怎么做,你能帮助我吗?
这是我的代码:
List<PartnerDomainDTO> domaines = partenaireHelper.allDomains();
ChoiceRenderer choiceRenderer = new ChoiceRenderer("label", "sid");
final Palette palette =
new Palette("partenaires", new PropertyModel(offre, "partenaires"), new Model(
(Serializable) partenairesPossibles), renderer, 10, false) {
private static final long serialVersionUID = 1178320215146881229L;
boolean first = true;
@Override
public Iterator getSelectedChoices() {
if (first) {
first = false;
return partenairesExistants.iterator();
}
return super.getSelectedChoices();
}
};
palette.setOutputMarkupId(true);
palette.setOutputMarkupPlaceholderTag(true);
DropDownChoice ddcdomaines = new DropDownChoice("domaines", new Model(domaines.get(0)), domaines, choiceRenderer);
ddcdomaines.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
remove(palette);
Palette palette1 =
new Palette(
"partenaires",
new PropertyModel(offre, "partenaires"),
new Model(new ArrayList<Partenaire>()),
renderer,
10,
false);
palette1.setOutputMarkupId(true);
palette1.setOutputMarkupPlaceholderTag(true);
add(palette1);
target.addComponent(palette);
target.addComponent(palette1);
}
});
add(palette);
add(ddcdomaines);
}
I created a palette which contains values, and i created a DropDownChoice ddcdomaines with an AjaxFormComponentUpdatingBehavior to update choice list, but i dont know how to do it, can you help me?
Here my code:
List<PartnerDomainDTO> domaines = partenaireHelper.allDomains();
ChoiceRenderer choiceRenderer = new ChoiceRenderer("label", "sid");
final Palette palette =
new Palette("partenaires", new PropertyModel(offre, "partenaires"), new Model(
(Serializable) partenairesPossibles), renderer, 10, false) {
private static final long serialVersionUID = 1178320215146881229L;
boolean first = true;
@Override
public Iterator getSelectedChoices() {
if (first) {
first = false;
return partenairesExistants.iterator();
}
return super.getSelectedChoices();
}
};
palette.setOutputMarkupId(true);
palette.setOutputMarkupPlaceholderTag(true);
DropDownChoice ddcdomaines = new DropDownChoice("domaines", new Model(domaines.get(0)), domaines, choiceRenderer);
ddcdomaines.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
remove(palette);
Palette palette1 =
new Palette(
"partenaires",
new PropertyModel(offre, "partenaires"),
new Model(new ArrayList<Partenaire>()),
renderer,
10,
false);
palette1.setOutputMarkupId(true);
palette1.setOutputMarkupPlaceholderTag(true);
add(palette1);
target.addComponent(palette);
target.addComponent(palette1);
}
});
add(palette);
add(ddcdomaines);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是使用 AjaxFormComponentUpdatingBehavior 的 DropDownChoice 的一个很好的示例:
http://wicketstuff.org/wicket/ajax/choice
单击“源代码”链接查看源代码。如果您需要更多信息,则需要在问题中提供更多详细信息。
更新:根据JavaDoc,有一种使用Ajax更新Palettes的特定方法:
http://wicket.apache.org/apidocs/1.4/org/apache/wicket/extensions/markup/html/form/palette/Palette.html
确保您按照这些说明进行操作做任何其他事情。
在您的代码中,您尝试删除一个调色板并放入另一个调色板。虽然从长远来看这可能有效,但它并不是很 Wicket 风格。遗憾的是,Palette 没有公共方法来更改选择。但是,如果您保留对 choiceModel 的引用,那么您可以修改该列表,并且调色板应该在重新渲染时看到更改。像这样的事情:
然后在 Ajax onUpdate 中
小心跟踪所选的选择和可能的选择。我不确定如果这些不匹配会发生什么。希望有帮助!
Here is an excellent example of DropDownChoice with AjaxFormComponentUpdatingBehavior:
http://wicketstuff.org/wicket/ajax/choice
Click on the Source Code link to see the source. If you need more information, than you need to provide more detail in your question.
Update: According to the JavaDoc, there is a specific way to update Palettes using Ajax:
http://wicket.apache.org/apidocs/1.4/org/apache/wicket/extensions/markup/html/form/palette/Palette.html
Make sure you follow those instructions before doing anything else.
In your code, you are attempting to remove one Palette and put in another Palette. While this might work in the long run, it is not very Wicket-y. Sadly, Palette does not have a public method to change the choices. However, if you keep a reference to your choicesModel, then you can modify that list and the Palette should see the change on re-render. Something like this:
And then in your Ajax onUpdate
Be careful with keeping track of the selected choices and the possible choices. I'm not sure what will happen if these don't match up. Hope that helps!