1

When a user clicks on the edit link in a wicket data grid component, a new window would open and they would modify whatever appears on the new form. In the datagrid, there are many rows. How can I get the index number of the row I want to edit? Please see below, the onclick event of the “edit” link.

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")));
Yandroide
  • 91
  • 1
  • 4
  • 13
  • 4
    Why do you need the index? You have the row model. This should be enough. – martin-g Mar 15 '15 at 15:51
  • Thanks for your help. This is a code I am maintaining and never learned wicket before. So big challenge for me. I will probably come back for other questions. Thanks... – Yandroide Mar 19 '15 at 18:59

1 Answers1

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();
        ...
    }
}
A.Alexander
  • 588
  • 3
  • 14