【问题标题】:Wicket CheckGoup get selected items markupIdsWicket CheckGoup 获取选中的项目 markupIds
【发布时间】:2014-05-12 05:51:10
【问题描述】:

是否可以从检票口中的检查组获取标记 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
        }

    });

有什么建议吗?

【问题讨论】:

  • 你需要它们做什么?
  • 我需要应用一些带有所选标记 ID 列表的 javascript 代码。

标签: java wicket wicket-1.6 wicket-6 wicketstuff


【解决方案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);
}

【讨论】:

  • group.getMarkupId 给出组的标记 id,而不是选定值的标记 id
  • 是的,您需要调用 ListItem 对象上的方法。您可以将它们添加到那里的列表中。
  • 这是可能的解决方案,但我认为应该是更好的解决方案,您可以从 checkgroup 获取所有 id
  • 您能否详细解释一下您想对这些项目做什么,是您想要更改的值吗?同样的变化适用于所有人吗?你想添加/删除东西吗?等等。
  • 我需要应用一些带有所选标记 ID 列表的 javascript 代码。
猜你喜欢
  • 2011-04-19
  • 2017-10-04
  • 1970-01-01
  • 2011-03-01
  • 2016-07-03
  • 1970-01-01
  • 2011-07-10
  • 2023-03-18
  • 2012-02-16
相关资源
最近更新 更多