Wicket,如何获取数据行索引号

时间:2015-03-14 23:11:31

标签: java wicket

当用户点击wicket数据网格组件中的编辑链接时,将打开一个新窗口,他们将修改新表单上显示的内容。在datagrid中,有很多行。如何获取要编辑的行的索引号?请参阅下面的“编辑”链接的onclick事件。

columnList.add(new AbstractLinkColumn<MyModel>(new Model<String>("Edit")) {

        @Override
        protected AbstractLink newLink(String componentId, final IModel<MyModel> rowModel) {
            return new AjaxLink<String>(componentId, getDisplayModel()) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    ModalWindow myModelWindow = requestForm.getmyModelWindow();
                    MyPanel panel = new MyPanel(myModelWindow.getContentId(), requestForm
                    .getModelObject(), myModelWindow, rowModel.getObject(), false, isSetReadOnly);
                    myModelWindow.setContent(panel);
                    Ricola.refresh(target, panel);
                    myModelWindow.show(target);
                }

            };
        }

        @Override
        protected Label newLinkLabel(String componentId, IModel<MyModel> rowModel) {
            return new Label(componentId, getDisplayModel());
        }

    }.setTooltip(new Model<String>("Click the Edit link to edit the line")));

1 个答案:

答案 0 :(得分:0)

public class MyColumn extends AbstractColumn {

    @Override
    public void populateItem(Item item, String componentId, IModel model) {
        Item rowItem = item.findParent(Item.class);
        int rowIndex = rowItem.getIndex();
        ...
    }
}