Search code examples
wicketjgrowl

JGrowlFeedbackPanel options don't work properly


I'm trying to use a JGrowlFeedbackPanel component in my project. It's a wicket adoption of the JGrowl plugin (JQuery). I got it from a maven's repository.

ResourceReference cssMenuRef = new ResourceReference(HomePage.class, "style_menu.css");
add(CSSPackageResource.getHeaderContribution(cssMenuRef));

JGrowlFeedbackPanel feedbackPanel = new JGrowlFeedbackPanel("feedbackPanel", new ErrorLevelFeedbackMessageFilter(FeedbackMessage.WARNING));
add(feedbackPanel);
Options errorOptions = new Options();
errorOptions.set("header", "Error"); //works
errorOptions.set("sticky", true); //works
errorOptions.set("position", "center"); //doesn't work
errorOptions.set("theme", "feedback"); //doesn't work
error("TEST!");
feedbackPanel.setErrorMessageOptions(errorOptions);

.feedback {
color: #ff0000;
background-color: #FFFFFF !important ; 
width: 400px;
}

I'd like to change jGrowl's defaut position and color, but they don't change at all. I can use the !important declaration in my css file, but I think it's not a good idea. I will appreciate any suggestions. Thanks!


Solution

  • For the position, jGrowl clearly says in it's documentation:

    This must be changed in the defaults before the startup method is called.

    Link: jGrowl

    -> According to the sourcecode I have found here : JGrowlFeedbackMessage.java and here: JGrowlFeedbackPanel.java This may not work the way it is done since you will have to go inside the "jquery.jgrowl.js" to modify the position default...

    Also I do not understand why the jGrowl options can't be completely extended in JS.

    Maybe a better advise would be to use jquery notifier, build your own panel and wrap the call to trigger notifications via the target.appendJavaScript() method. Example for wicket6:

        public void showExpiringNotification(final String title, final String message, final int expiringSpeed) {
          AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
          if (target != null) {
            target.appendJavaScript("$('#container').notify('create','error',{title: '" + title + "', text: '" + message
                    + "' },{expires: " + expiringSpeed + "})");
          }
        }
    

    If needed I might give a more detailed example on my blog...