Question

I have an IFeedback component on my html, and it shows messages if something happens, etc: I upload a file, and a message will inform me: 1 file upload successfully. And what I want is to close this message peace. How could I do it? If I refresh the page, the message will disappear, but I want to create a button, or a link, to click on it, and than the message will close/disappear. Can anyone give me an example, or some help?

Was it helpful?

Solution

You can add an AjaxEventBehavior that add's a click handler to your component and when it's clicked it will disappear. Here example code with an FeedbackPanel:

private FeedbackPanel feedbackPanel() {
    final FeedbackPanel fb = new FeedbackPanel("feedbackPanel") {
        @Override
        protected void onConfigure() {
            super.onConfigure();
            setVisible(anyMessage());
        }
    };
    fb.add(new AjaxEventBehavior("click") {
        @Override
        protected void onEvent(AjaxRequestTarget target) {
          fb.setVisible(false);
          target.add(fb);
        }
    });
    fb.setOutputMarkupPlaceholderTag(true);
    return fb;
}

OTHER TIPS

You can close the item in a "regular" way by attaching Wicket AjaxLink to it and setting the visibility to false onClick (you need to add the item to AjaxRequestTarget). The method has one disadvantage: You need two Ajax calls. One to show the IFeedbck item and the second to close it.

Another way to implement this is by adding custom AJAX call listener (in javascript). Subscribe to the global event '/ajax/call/success':


Wicket.Event.subscribe('/ajax/call/success',
    function(jqEvent, attributes, jqXHR, errorThrown, textStatus) {
        attachCloseHandler();
    }
);

and implement attachCloseHandler() function to attach close handlers to your IFeedback items. In the most general case this is just something like:


$('#my-container-with-feedback-items .my-feedback-item').click( function(e) { 
// close the item 
});

You should check '/ajax/call/success' callback to see if the event relates to the feedback item to avoid calling the function every time.

The second implementation makes only one Ajax call: When the item gets rendered. The closing is done only in javascript and you don't have additional Ajax call.

Reference: http://wicket.apache.org/guide/guide/chapter17.html#chapter17_5

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top