Search code examples
javaajaxwicket

Apache Wicket - FeedbackPanel doesn't refresh


I'm currently working a table in Apache Wicket with a FeedbackPanel. I have different columns and one column is for deleting entries in the table. As soon as I press the Icon of the column to delete an entry, the entry gets deleted, but the feedbackpanel doesn't refresh.

But it's important that both components get refreshed. Both components have the "setOutputMarkupId(true)"

columnsDaten.add(new AbstractColumn<>(new Model<>(""))
{
    @Override
    public void populateItem(Item<ICellPopulator<Filterbedingungen>> item, String componentId, IModel<Filterbedingungen> rowModel)
    {
        item.add(new LinkPanelAjax(componentId, Model.of(""), "fa fa-trash")
            {
                @Override
                public void onClickEvent(AjaxRequestTarget target)
                {
                    Integer count = filterbedingungService.countKonfigurationen4Bedingung(rowModel.getObject().getBedingung());
                    if (count == 0)
                    {
                        filterbedingungService.loeschen(rowModel.getObject());
                        suchergebnis = filteredSuchergebnis(true, suchFilterText.getModelObject());
                        success(String.format("Filterbedingung %s gelöscht", rowModel.getObject().getBedingung()));
                        setResponsePage(FilterbedingungenVerwaltungPage.class);
                    }
                    else
                    {
                        error(String.format("Die Filterbedingung %s kann nicht gelöscht werden, da sie noch in verschiedenen Dokumententensets verwendet wird.", rowModel.getObject().getBedingung()));
                    }
                    target.add(feedback);
                }
            })
            .add(AttributeModifier.append("title", String.format("Filterbingung %s löschen", rowModel.getObject().getBedingung())));
    }
});

Even AI can't help me with this problem.

I tried different approaches to refresh the different components. Once I tried to refresh the table and the feedbackpanel, but when I do that, only the table gets refreshed.

If I only refresh the feedbackpanel without the datatable, then I get the feedback messages but the datatable (obviously) doesn't refresh.


Solution

  • success(String.format("Filterbedingung %s gelöscht", rowModel.getObject().getBedingung()));
                        
    setResponsePage(FilterbedingungenVerwaltungPage.class);
    

    Here with the call to success(...) you register a feedback message for a component in the current page (Java) instance. Then you call setResponsePage(Class<Page>) - thus redirecting to a new Java page instance and the feedback message is no more in scope.

    You should use Session.get().success(...) if you want the message to survive such redirects, a.k.a. flash scoped feedback.

    Does the error case work ? There is no redirect, so I'd expect it to work fine.