2
votes

I have couple of drop downdowns and a download link button. Based on the user selection, i get the file to be downloaded. if the user did not make a selection I show an error on the feedback panel. if the user then makes a selection and clicks on download link it works fine, but the previous feedback message is still visible. How do I clear it.

onclick of the download link, i tried the following, but no use

FeedbackMessages me = Session.get().getFeedbackMessages(); 
me.clear();
3
Can you provide some more details: Is the download link an SubmitLink? Are you using Ajax with AjaxSubmitLink? In normal case it is not necessary to clean the FeedbackMessages by your self. - mrak
It is a Ajax download link - user373201
Did you try to add the FeedbackPanel to AjaxRequestTarget? - mrak

3 Answers

4
votes

Probably it is

Session.get().cleanupFeedbackMessages()

even it has been changed in Wicket 6.x

2
votes

I've found this post and I think it is time to share the way for Wicket 6.x and for Wicket 7.x, because Session.get().cleanupFeedbackMessages() was deprecated already.

To do it for Wicket 6.x you have to implement additional filter for the feedback panel. Where to do it, it is your decision to decide.

Create a new FeedbackPanel implementation by extending from the existing FeedBackPanel class

private class MessagesFeedbackPanel extends FeedbackPanel{

  private MessageFilter filter = new MessageFilter();

  public MessagesFeedbackPanel(String id){
    super(id);
    setFilter(filter);
  }


  @Override
  protected void onBeforeRender(){
    super.onBeforeRender();
    // clear old messages
    filter.clearMessages();
  }
}

Provide a new Filter implementation, by implementing the existing IFeedbackMessageFilter interface

public class MessageFilter implements IFeedbackMessageFilter{

  List<FeedbackMessage> messages = new ArrayList<FeedbackMessage>();

  public void clearMessages(){
    messages.clear();
  }

  @Override
  public boolean accept(FeedbackMessage currentMessage){
    for(FeedbackMessage message: messages){
      if(message.getMessage().toString().equals(currentMessage.getMessage().toString()))
        return false;
    }
    messages.add(currentMessage);
    return true;
 }
}
0
votes

Following code works for me in Wicket 6:

public class MyComponent extends Panel {

    ...
    FeedbackMessages feedback = getFeedbackMessages();
    feedback.clear();