2

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?

falconw
  • 59
  • 5

1 Answers1

1

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);
}
Martin
  • 1,274
  • 12
  • 23
  • group.getMarkupId gives markup id of group,not of selected values – falconw May 12 '14 at 07:43
  • 1
    yes, you need to call the method on the ListItem objects. You can add them to a list there. – Martin May 12 '14 at 10:08
  • This is possible solution, but i think should be a better one, where you can get all ids from checkgroup – falconw May 12 '14 at 10:21
  • Could you explain a bit more about what you want to do with the Items, is it the value you want to change? does the same change apply to all? Do you want to add/remove stuff? etc.. – Martin May 12 '14 at 11:36
  • i need to apply some javascript code with list of selected markup ids. – falconw May 12 '14 at 11:46