是否可以从wicket中的checkgroup获取标记ID,我有以下代码
Form f = new Form("form");
add(f);
final CheckGroup group = new CheckGroup("group", new ArrayList<Person>());
f.add(group);
group.add(new CheckGroupSelector("groupselector"));
ListView persons = new ListView("persons", getPersons()) {
@Override
protected void populateItem(ListItem item) {
item.add(new Check("checkbox", item.getModel()));
item.add(new Label("name", new PropertyModel(item.getModel(), "name")));
item.add(new Label("lastName", new PropertyModel(item.getModel(), "surname")));
}
};
persons.setReuseItems(true);
group.add(persons);
f.add(new AjaxSubmitLink("submit") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
System.out.println(((List)group.getModelObject()).size());
// need to get group markup ids here
}
});
有什么建议吗?
答案 0 :(得分:1)
这是Component.getMarkupId()的文档。因此,您需要访问组件才能获得MarkupId并执行您想要执行的操作。
/**
* Retrieves id by which this component is represented within the markup. This is either the id
* attribute set explicitly via a call to {@link #setMarkupId(String)}, id attribute defined in
* the markup, or an automatically generated id - in that order.
* <p>
* If no explicit id is set this function will generate an id value that will be unique in the
* page. This is the preferred way as there is no chance of id collision.
* <p>
* Note: This method should only be called after the component or its parent have been added to
* the page.
*
* @return markup id of the component
*/
public String getMarkupId()
{
return getMarkupId(true);
}