简体   繁体   中英

How do I use FeedbackPanel in a stateless Wicket application?

I have an application using FeedbackPanel to show the user the results of posting forms.

On calling Component#info(String) on pages which are stateless, Wicket does appear to be putting that string into the FeedbackMessages session. However later on, FeedbackPanel tries to find the messages and doesn't seem to be able to find any at all, even though they still appear to be in the session when I view all this in a debugger.

Also, when this occurs, WicketTester swears that the message is being displayed, making WicketTester essentially useless for testing feedback messages (I now have a TODO on my list to replace usage of that with assertions on the markup itself.)

Answering my question with my own solution. In our StatelessWebSession , override an additional method:

private static final IFeedbackMessageFilter renderedMessagesForComponents =
    new IFeedbackMessageFilter()
    {
        @Override
        public boolean accept(FeedbackMessage message)
        {
            return message.getReporter() != null && message.isRendered();
        }
    };

@Override
protected void cleanupComponentFeedbackMessages()
{
    // deliberately not calling the method in the superclass because it
    // clears all messages for components.
    getFeedbackMessages().clear(renderedMessagesForComponents);
}

This way it only clears rendered messages for components instead of all messages for components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM