Example usage for org.apache.wicket.feedback FeedbackCollector collect

List of usage examples for org.apache.wicket.feedback FeedbackCollector collect

Introduction

In this page you can find the example usage for org.apache.wicket.feedback FeedbackCollector collect.

Prototype

public final List<FeedbackMessage> collect() 

Source Link

Document

Collects all feedback messages

Usage

From source file:org.efaps.ui.wicket.behaviors.AjaxFieldUpdateBehavior.java

License:Apache License

/**
 * Default means nothing is done on error.
 *
 * @see org.apache.wicket.ajax.form.AjaxFormSubmitBehavior#onError(org.apache.wicket.ajax.AjaxRequestTarget)
 * @param _target AjaxRequestTarget/*  w w  w .j  av a  2 s. co m*/
 */
@Override
protected void onError(final AjaxRequestTarget _target) {
    if (this.errorHandling) {
        final FeedbackCollector collector = new FeedbackCollector(getForm().getPage());
        final List<FeedbackMessage> msgs = collector.collect();
        final StringBuilder html = new StringBuilder()
                .append("<table class=\"eFapsValidateFieldValuesTable\">");
        for (final FeedbackMessage msg : msgs) {
            msg.getReporter().add(AttributeModifier.append("class", "invalid"));
            _target.add(msg.getReporter());
            Serializable warn = null;
            if (msg.getMessage() instanceof ValidationErrorFeedback) {
                // look if a message was set
                warn = ((ValidationErrorFeedback) msg.getMessage()).getMessage();
                // still no message, create one
                if (warn == null) {
                    warn = ((ValidationErrorFeedback) msg.getMessage()).getError()
                            .getErrorMessage(new ErrorMessageResource());
                }
            }
            String label = "";
            if (msg.getReporter() instanceof IFieldConfig) {
                label = ((IFieldConfig) msg.getReporter()).getFieldConfig().getLabel();
            }
            html.append("<tr><td>").append(label).append(":</td><td>").append(warn).append("</td></tr>");
        }
        html.append("</table>");

        final ModalWindowContainer modal = ((AbstractContentPage) getComponent().getPage()).getModal();

        modal.setInitialWidth(350);
        modal.setInitialHeight(200);

        modal.setPageCreator(new ModalWindow.PageCreator() {

            private static final long serialVersionUID = 1L;

            @Override
            public Page createPage() {
                return new DialogPage(((AbstractContentPage) getComponent().getPage()).getPageReference(),
                        html.toString(), true, false);
            }
        });
        modal.show(_target);
    }
}

From source file:org.efaps.ui.wicket.components.footer.AjaxSubmitCloseBehavior.java

License:Apache License

/**
 * Method is not used, but needed from the api.
 *
 * @param _target AjaxRequestTarget/*from   w w  w  . jav a  2s  .  co m*/
 */
@Override
protected void onError(final AjaxRequestTarget _target) {
    final FeedbackCollector collector = new FeedbackCollector(getForm().getPage());
    final List<FeedbackMessage> msgs = collector.collect();
    final ErrorMessageResource msgResource = new ErrorMessageResource();
    final StringBuilder html = new StringBuilder().append("<table class=\"eFapsValidateFieldValuesTable\">");
    for (final FeedbackMessage msg : msgs) {
        if (!(msg.getReporter() instanceof Form)) {
            if (msg.getReporter() instanceof AutoCompleteComboBox) {
                final StringBuilder js = new StringBuilder()
                        .append("require(['dojo/dom','dojo/dom-class'], function (dom, domClass) {")
                        .append("domClass.add(dom.byId('").append(msg.getReporter().getMarkupId())
                        .append("').parentNode, 'invalid');").append("});");
                _target.prependJavaScript(js);
            } else {
                msg.getReporter().add(AttributeModifier.append("class", "invalid"));
                _target.add(msg.getReporter());
            }
        }
        Serializable warn = null;
        if (msg.getMessage() instanceof ValidationErrorFeedback) {
            // look if a message was set
            warn = ((ValidationErrorFeedback) msg.getMessage()).getMessage();
            // still no message, create one
            if (warn == null) {
                warn = ((ValidationErrorFeedback) msg.getMessage()).getError().getErrorMessage(msgResource);
            }
        } else {
            warn = String.valueOf(msg.getMessage());
        }
        html.append("<tr>");
        if (msg.getReporter() instanceof IFieldConfig) {
            html.append("<td>").append(((IFieldConfig) msg.getReporter()).getFieldConfig().getLabel())
                    .append(":</td><td>").append(warn).append("</td>");
        } else {
            html.append("<td colspan=\"2\">").append(warn).append("</td></tr>");
        }
        msg.getReporter().getFeedbackMessages().clear();
    }
    html.append("</table>");
    showDialog(_target, html.toString(), true, false);

    // after every commit the fieldset must be resteted
    getForm().getPage().visitChildren(SetDataGrid.class, new IVisitor<SetDataGrid, Void>() {

        @Override
        public void component(final SetDataGrid _setDataGrid, final IVisit<Void> _visit) {
            final UIFieldSet fieldSet = (UIFieldSet) _setDataGrid.getDefaultModelObject();
            fieldSet.resetIndex();
        }
    });
    getForm().getPage().visitChildren(DropDownField.class, new IVisitor<DropDownField, Void>() {

        @Override
        public void component(final DropDownField _dropDown, final IVisit<Void> _visit) {
            _dropDown.setConverted(false);
        }
    });
}