Example usage for org.apache.wicket.ajax.attributes AjaxCallListener onBefore

List of usage examples for org.apache.wicket.ajax.attributes AjaxCallListener onBefore

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.attributes AjaxCallListener onBefore.

Prototype

public AjaxCallListener onBefore(final CharSequence before) 

Source Link

Document

Sets the JavaScript code that will be returned by #getBeforeHandler(Component) .

Usage

From source file:com.googlecode.wicket.jquery.ui.widget.dialog.ButtonAjaxBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    if (this.button.isIndicating()) {
        AjaxCallListener ajaxCallListener = new AjaxCallListener();
        ajaxCallListener.onBefore(this.getBeforeStatement());
        ajaxCallListener.onSuccess(this.getFinishStatement());
        ajaxCallListener.onFailure(this.getFinishStatement());

        attributes.getAjaxCallListeners().add(ajaxCallListener);
    }/*from  w w  w  .  j  a  v a 2s .  c o  m*/
}

From source file:com.wicketinaction.HandlebarsButton.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    // let Wicket.Ajax/jQuery know that the result is JSON so it will parse it for you
    attributes.setDataType("json");

    // tell Wicket.Ajax to not try to process the Ajax response because it is not the normal <ajax-response>
    attributes.setWicketAjaxResponse(false);

    // register the onSuccess listener that will execute Handlebars logic
    AjaxCallListener listener = new AjaxCallListener() {
        @Override/*from   www  . j  a  v  a2s.co m*/
        public CharSequence getSuccessHandler(Component component) {
            // returns an instance of JsonFunction, so Wicket will render it as is
            return onSuccessFunction;
        }
    };

    // the following handlers are not JsonFunction and they will be wrapped in JsonFunction by Wicket and the
    // appropriate parameters will be passed.

    // For the 'before' handler it looks like: function(attrs, jqXHR, settings){Wicket.Log.info('[Wicket Ajax 6 demo]: executing a before handler');}
    listener.onBefore("Wicket.Log.info('[Wicket Ajax 6 demo]: executing a before handler');");

    // For the 'complete' handler it looks like: function(attrs, jqXHR, textStatus){Wicket.Log.info('[Wicket Ajax 6 demo]: executing a complete handler');}
    listener.onComplete(
            "Wicket.Log.info('[Wicket Ajax 6 demo]: executing a complete handler. Status: ' + textStatus);");

    // change the return to 'false' and the Ajax call wont be executed at all.
    listener.onPrecondition("return true;");

    attributes.getAjaxCallListeners().add(listener);
}

From source file:org.efaps.ui.wicket.components.menutree.AjaxRemoveLink.java

License:Apache License

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes _attributes) {
    super.updateAjaxAttributes(_attributes);
    final AjaxCallListener listener = new AjaxCallListener();
    final StringBuilder js = new StringBuilder();
    final MenuTree menuTree = findParent(MenuTree.class);
    final String key = RandomStringUtils.randomAlphabetic(6);
    menuTree.add(key, (UIMenuItem) getDefaultModelObject());
    js.append("require([\"dijit/registry\",\"dojo/dom-construct\"], function(registry, domConstruct){ ")
            .append("registry.byId(\"").append(((ContentContainerPage) getPage()).getCenterPanelId())
            .append("\").set(\"content\", domConstruct.create(\"iframe\", {").append("\"src\": \"")
            .append(menuTree.urlFor(ILinkListener.INTERFACE, new PageParameters())).append("&D=").append(key)
            .append("\",\"style\": \"border: 0; width: 100%; height: 99%\"").append("})); ").append("});");
    listener.onBefore(js);
    _attributes.getAjaxCallListeners().add(listener);
}

From source file:org.efaps.ui.wicket.components.search.DimValuePanel.java

License:Apache License

/**
 * Instantiates a new dim value panel./*from   w w  w.  j  a  v a  2  s.  co m*/
 *
 * @param _id the id
 * @param _model the model
 */
public DimValuePanel(final String _id, final IModel<DimTreeNode> _model) {
    super(_id, _model);
    final WebMarkupContainer cont = new WebMarkupContainer("triStateDiv");
    cont.setOutputMarkupId(true);

    if (_model.getObject().getStatus() != null) {
        cont.add(new AttributeAppender("class", _model.getObject().getStatus() ? "on" : "off", " "));
    }

    add(cont);

    final AjaxButton btn = new AjaxButton("triStateBtn") {
        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes _attributes) {
            super.updateAjaxAttributes(_attributes);
            final AjaxCallListener lstnr = new AjaxCallListener();
            lstnr.onBefore(getJavaScript());
            _attributes.getAjaxCallListeners().add(lstnr);
        }
    };
    cont.add(btn);

    cont.add(new Label("label", _model.getObject().getLabel()));
    cont.add(new Label("value", String.valueOf(((DimValue) _model.getObject().getValue()).getValue())));

    cont.add(new HiddenField<Boolean>("triStateValue", PropertyModel.of(_model.getObject(), "status")) {

        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isInputNullable() {
            return true;
        };

        @Override
        protected String getModelValue() {
            final Boolean val = (Boolean) getDefaultModelObject();
            final String ret;
            if (BooleanUtils.isFalse(val)) {
                ret = "off";
            } else if (BooleanUtils.isTrue(val)) {
                ret = "on";
            } else {
                ret = "";
            }
            return ret;
        };

    }.setOutputMarkupId(true));
}

From source file:org.wicketstuff.jquery.block.BlockingAjaxLink.java

License:Apache License

/**
 * Returns ajax call decorator that will be used to decorate the ajax call.
 *
 * @return ajax call decorator//from  w  ww .java2 s.  com
 */
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    AjaxCallListener ajaxCallListener = new AjaxCallListener();
    StringBuilder js = new StringBuilder();
    CharSequence sel = getBlockElementsSelector();
    if (sel != null) {
        js.append("$('").append(sel).append("').block( ");
    } else {
        js.append("$.blockUI( ");
    }
    js.append(options.toString()).append(" ); ");

    ajaxCallListener.onBefore(js);
}