Search in sources :

Example 1 with FeedbackMessage

use of org.apache.wicket.feedback.FeedbackMessage in project hale by halestudio.

the class FieldMessage method onBeforeRender.

/**
 * @see Component#onBeforeRender()
 */
@Override
protected void onBeforeRender() {
    super.onBeforeRender();
    // collector.collect();
    List<FeedbackMessage> msgs = formComponent.getFeedbackMessages().toList();
    // only collect the last message (XXX correct like this?)
    FeedbackMessage msg = (msgs.isEmpty()) ? (null) : (msgs.get(msgs.size() - 1));
    if (msg != null) {
        setDefaultModel(new Model<Serializable>(msg.getMessage()));
        add(new AttributeModifier("class", new Model<String>(getCssClass(msg.getLevelAsString()))));
    } else {
        if (specialValidStyle && formComponent.isValid() && formComponent.checkRequired()) {
            setDefaultModel(new Model<String>(""));
            add(new AttributeModifier("class", new Model<String>(getValidCssClass())));
        } else {
            setDefaultModel(text);
            add(new AttributeModifier("class", new Model<String>(getDefaultCssClass())));
        }
    }
}
Also used : Serializable(java.io.Serializable) Model(org.apache.wicket.model.Model) IModel(org.apache.wicket.model.IModel) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) AttributeModifier(org.apache.wicket.AttributeModifier)

Example 2 with FeedbackMessage

use of org.apache.wicket.feedback.FeedbackMessage in project ocvn by devgateway.

the class FileInputBootstrapFormComponentWrapper method addFileUploadFeedbackComponent.

private void addFileUploadFeedbackComponent() {
    fileUploadFeedback.setOutputMarkupId(true);
    // show only the messages (fatal, success) generated by this component
    fileUploadFeedback.setFilter(new IFeedbackMessageFilter() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean accept(final FeedbackMessage message) {
            final Component reporter = message.getReporter();
            // for example errors like 'FIELD is required.'
            if (message.getLevel() == FeedbackMessage.ERROR) {
                return false;
            }
            return reporter != null && (FileInputBootstrapFormComponentWrapper.this.contains(reporter, true) || Objects.equal(FileInputBootstrapFormComponentWrapper.this, reporter));
        }
    });
    add(fileUploadFeedback);
}
Also used : IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) FormComponent(org.apache.wicket.markup.html.form.FormComponent) Component(org.apache.wicket.Component)

Example 3 with FeedbackMessage

use of org.apache.wicket.feedback.FeedbackMessage in project wicket by apache.

the class WicketTester method assertFeedback.

/**
 * Assert that a particular feedback panel is rendering certain messages.
 *
 * NOTE: this casts the component at the specified path to a {@link FeedbackPanel}, so it will
 * not work with custom {@link IFeedback} implementations unless you are subclassing
 * {@link FeedbackPanel}
 *
 * @param path
 *            path to the feedback panel
 * @param messages
 *            messages expected to be rendered
 */
public void assertFeedback(String path, Serializable... messages) {
    final FeedbackPanel fbp = (FeedbackPanel) getComponentFromLastRenderedPage(path);
    final IModel<List<FeedbackMessage>> model = fbp.getFeedbackMessagesModel();
    final List<FeedbackMessage> renderedMessages = model.getObject();
    if (renderedMessages == null) {
        fail(String.format("feedback panel at path [%s] returned null messages", path));
    }
    if (messages.length != renderedMessages.size()) {
        fail(String.format("you expected '%d' messages for the feedback panel [%s], but there were actually '%d'", messages.length, path, renderedMessages.size()));
    }
    for (int i = 0; i < messages.length && i < renderedMessages.size(); i++) {
        final Serializable expected = messages[i];
        boolean found = false;
        for (FeedbackMessage actual : renderedMessages) {
            if (Objects.equal(expected, actual.getMessage())) {
                found = true;
                break;
            }
        }
        if (!found) {
            assertResult(Result.fail("Missing expected feedback message: " + expected));
        }
    }
}
Also used : FeedbackPanel(org.apache.wicket.markup.html.panel.FeedbackPanel) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) List(java.util.List) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage)

Example 4 with FeedbackMessage

use of org.apache.wicket.feedback.FeedbackMessage in project midpoint by Evolveum.

the class FeedbackListView method populateItem.

@Override
protected void populateItem(final ListItem<FeedbackMessage> item) {
    final FeedbackMessage message = item.getModelObject();
    if (message.getMessage() instanceof OpResult) {
        final OpResult opResult = (OpResult) message.getMessage();
        OperationResultPanel panel = new OperationResultPanel("message", Model.of(opResult)) {

            private static final long serialVersionUID = 1L;

            @Override
            public void close(AjaxRequestTarget target) {
                super.close(target);
                message.markRendered();
            }

            protected void onAfterRender() {
                opResult.setAlreadyShown(true);
                super.onAfterRender();
            }
        };
        panel.add(new VisibleBehaviour(() -> opResult != null && !opResult.isAlreadyShown()));
        panel.setOutputMarkupId(true);
        item.add(panel);
    } else {
        message.markRendered();
        ValidationErrorPanel validationPanel = new ValidationErrorPanel("message", item.getModel()) {

            private static final long serialVersionUID = 1L;

            @Override
            public void close(AjaxRequestTarget target) {
                super.close(target);
                message.markRendered();
            }
        };
        validationPanel.setOutputMarkupId(true);
        item.add(validationPanel);
    }
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ValidationErrorPanel(com.evolveum.midpoint.gui.api.component.result.ValidationErrorPanel) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) OpResult(com.evolveum.midpoint.gui.api.component.result.OpResult) OperationResultPanel(com.evolveum.midpoint.gui.api.component.result.OperationResultPanel) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage)

Example 5 with FeedbackMessage

use of org.apache.wicket.feedback.FeedbackMessage in project oc-explorer by devgateway.

the class FileInputBootstrapFormComponentWrapper method addFileUploadFeedbackComponent.

private void addFileUploadFeedbackComponent() {
    fileUploadFeedback.setOutputMarkupId(true);
    // show only the messages (fatal, success) generated by this component
    fileUploadFeedback.setFilter(new IFeedbackMessageFilter() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean accept(final FeedbackMessage message) {
            final Component reporter = message.getReporter();
            // for example errors like 'FIELD is required.'
            if (message.getLevel() == FeedbackMessage.ERROR) {
                return false;
            }
            return reporter != null && (FileInputBootstrapFormComponentWrapper.this.contains(reporter, true) || Objects.equal(FileInputBootstrapFormComponentWrapper.this, reporter));
        }
    });
    add(fileUploadFeedback);
}
Also used : IFeedbackMessageFilter(org.apache.wicket.feedback.IFeedbackMessageFilter) FeedbackMessage(org.apache.wicket.feedback.FeedbackMessage) FormComponent(org.apache.wicket.markup.html.form.FormComponent) Component(org.apache.wicket.Component)

Aggregations

FeedbackMessage (org.apache.wicket.feedback.FeedbackMessage)14 Serializable (java.io.Serializable)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 FormComponent (org.apache.wicket.markup.html.form.FormComponent)3 VisibleBehaviour (com.evolveum.midpoint.web.component.util.VisibleBehaviour)2 Component (org.apache.wicket.Component)2 FeedbackMessages (org.apache.wicket.feedback.FeedbackMessages)2 IFeedbackMessageFilter (org.apache.wicket.feedback.IFeedbackMessageFilter)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 IModel (org.apache.wicket.model.IModel)2 OpResult (com.evolveum.midpoint.gui.api.component.result.OpResult)1 OperationResultPanel (com.evolveum.midpoint.gui.api.component.result.OperationResultPanel)1 ValidationErrorPanel (com.evolveum.midpoint.gui.api.component.result.ValidationErrorPanel)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)1 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)1 FeedbackAlerts (com.evolveum.midpoint.web.component.message.FeedbackAlerts)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AttributeModifier (org.apache.wicket.AttributeModifier)1