Thomas S.
Thomas S.

Reputation: 6335

Wicket: what link to use for action + redirect to current page

Though I'm using Wicket for a couple of years now, I still don't understand what link component to use for this scenario:

I want to show a stateless bookmarkable page that lists a couple of entries from a database which is queries by a couple of page parameters of that bookmarkable page. Each of these entries should be deletable (with an ordinary confirmation dialog). After confirming the modal "Are you sure to delete this item" dialog, it should redirect to the same stateless bookmarkable page, so the same page parameters cause the database to be queried again and now show the entries after the delete.

I've created a DataView component with ListDataProvider to show the entries. The delete link is created like this:

... new ListDataProvider<>(entries) {
public void populateItem(Item<MyEntry> item) {
    final MyEntry entry = item.getModelObject();
    ...


    item.add(new Link<Long>("delete", Model.of(entry.getId())) {
        public void onClick() {
          // todo: delete
          System.out.println("delete " + getModelObject().longValue());
          getRequestCycle().setResponsePage(MyPage.class, getPageParameters());
        }
    }
    ...
}

Unfortunately, the page version number increases with each "Delete" click.

Upvotes: 0

Views: 172

Answers (1)

martin-g
martin-g

Reputation: 17513

If the page already had pageId in the url then it is not stateless in first place.

In your case you ask for StatelessLink. But you have to make sure you don't use any other stateful components in the page. You can use wicket-devutils' StatelessChecker listener to find what else is stateful.

Upvotes: 2

Related Questions