Example usage for org.apache.wicket.feedback FeedbackMessages first

List of usage examples for org.apache.wicket.feedback FeedbackMessages first

Introduction

In this page you can find the example usage for org.apache.wicket.feedback FeedbackMessages first.

Prototype

public final FeedbackMessage first() 

Source Link

Document

Retrieves the first message

Usage

From source file:guru.mmp.application.web.template.util.FeedbackUtil.java

License:Apache License

/**
 * Generate the Javascript to display the feedback for the specified component.
 *
 * @param id                     the id of the component to provide the feedback for
 * @param component              the component to generate the feedback JavaScript for
 * @param isAjaxRequest          is feedback being generated as part of an Ajax request
 * @param feedbackMessageClasses the additional CSS classes to apply to the feedback message
 *
 * @return the JavaScript to display the feedback message or <code>null</code>
 *         if there is no feedback for the specified component
 *///from   w  w  w . j  a v  a 2 s. c  o  m
public static String generateFeedbackJavaScript(String id, Component component, boolean isAjaxRequest,
        String feedbackMessageClasses) {
    if (component.hasFeedbackMessage()) {
        FeedbackMessages feedbackMessages = component.getFeedbackMessages();

        FeedbackMessage feedbackMessage = feedbackMessages.first();

        String feedbackClass = null;

        if (feedbackMessage.isError()) {
            feedbackClass = "has-error";
        } else if (feedbackMessage.isFatal()) {
            feedbackClass = "has-error";
        } else if (feedbackMessage.isWarning()) {
            feedbackClass = "has-warning";
        } else if (feedbackMessage.isInfo()) {
            feedbackClass = "has-info";
        } else if (feedbackMessage.isDebug()) {
            feedbackClass = "has-success";
        }

        String javaScript = String.format(
                isAjaxRequest ? SHOW_FORM_COMPONENT_FEEDBACK_JAVA_SCRIPT
                        : DOM_READY_SHOW_FORM_COMPONENT_FEEDBACK_JAVA_SCRIPT,
                id, feedbackClass, StringUtil.notNull(feedbackMessageClasses),
                JavaScriptUtils.escapeQuotes(feedbackMessage.getMessage().toString()));

        // Clear the feedback messages for the component
        for (FeedbackMessage componentFeedbackMessage : feedbackMessages) {
            componentFeedbackMessage.markRendered();
        }

        return javaScript;
    } else {
        if (isAjaxRequest) {
            return String.format(CLEAR_FORM_COMPONENT_FEEDBACK_JAVA_SCRIPT, id);
        }

        return null;
    }
}

From source file:org.dcm4chee.wizard.common.behavior.MarkInvalidBehavior.java

License:LGPL

@Override
public void beforeRender(Component component) {
    msg = null;//from ww  w . j av a 2s.  c o m
    if (component instanceof FormComponent<?>) {
        FormComponent<?> fc = (FormComponent<?>) component;
        if (!fc.isValid()) {
            FeedbackMessages fbMsg = fc.getFeedbackMessages();
            msg = fbMsg != null ? msg = fbMsg.first().getMessage().toString() : "";
            if (fbMsg != null)
                fbMsg.first().markRendered();
        }
    }
}

From source file:pl.doa.wicket.ui.feedback.FeedbackLabel.java

License:Apache License

/**
 * Set the content of this FeedbackLabel, depending on if the component has
 * a FeedbackMessage./*  w ww.java 2  s. com*/
 * <p/>
 * The HTML class attribute will be filled with the error level of the
 * feedback message. That way, you can easily style different messages
 * differently. Examples:
 * <p/>
 * class = "feedbacklabel INFO" class = "feedbacklabel ERROR" class =
 * "feedbacklabel DEBUG" class = "feedbacklabel FATAL"
 *
 * @see Component
 */
@Override
protected void onBeforeRender() {
    super.onBeforeRender();
    this.setDefaultModel(null);

    FeedbackMessages messages = component.getFeedbackMessages();
    if (messages != null) {
        if (this.text != null) {
            this.setDefaultModel(text);
        } else {
            for (FeedbackMessage message : messages) {
                // rendering first available message
                if (message.isRendered()) {
                    continue;
                }
                message.markRendered();
                setDefaultModel(new Model<Serializable>(message.getMessage()));
                break;
            }
        }

        this.add(new AttributeModifier("class", new Model(getCssClass(messages.first()))));
    } else {
        this.setDefaultModel(null);
    }
}