Wicket checkgroup获得选中的项目标记id



是否可以从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
        }
    });

有什么建议吗?

这是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);
}

相关内容

最新更新