Search code examples
javawicketwicket-1.6wicket-6wicketstuff

Wicket CheckGoup get selected items markupIds


Is it possible to get markup id's from checkgroup in wicket, i have the following code

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
        }

    });

Any suggestions?


Solution

  • This is the documentation for Component.getMarkupId(). So you need access to the components to get MarkupId's and do what you want to do.

     /**
     * 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);
    }