Search in sources :

Example 11 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxFormChoiceComponentUpdatingBehavior method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    attributes.setSerializeRecursively(true);
    attributes.getAjaxCallListeners().add(new AjaxCallListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public CharSequence getPrecondition(Component component) {
            return String.format("return attrs.event.target.name === '%s'", getFormComponent().getInputName());
        }
    });
}
Also used : Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 12 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxEditableMultiLineLabel method newEditor.

@Override
protected FormComponent<T> newEditor(final MarkupContainer parent, final String componentId, final IModel<T> model) {
    TextArea<T> editor = new TextArea<T>(componentId, model) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onModelChanged() {
            AjaxEditableMultiLineLabel.this.onModelChanged();
        }

        @Override
        protected void onModelChanging() {
            AjaxEditableMultiLineLabel.this.onModelChanging();
        }
    };
    editor.add(new AttributeModifier("rows", (IModel<Integer>) () -> rows));
    editor.add(new AttributeModifier("cols", (IModel<Integer>) () -> cols));
    editor.setOutputMarkupId(true);
    editor.setVisible(false);
    editor.add(new EditorAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.setMethod(Method.POST);
            attributes.setEventNames("blur", "keyup");
            CharSequence dynamicExtraParameters = "var result = [], " + "kc=Wicket.Event.keyCode(attrs.event)," + "evtType=attrs.event.type;" + "if (evtType === 'keyup') {" + // ESCAPE key
            "if (kc===27) { result.push( { name: 'save', value: false } ); }" + "}" + "else if (evtType==='blur') { result = Wicket.Form.serializeElement(attrs.c); result.push( { name: 'save', value: true } ); }" + "return result;";
            attributes.getDynamicExtraParameters().add(dynamicExtraParameters);
            CharSequence precondition = "var kc=Wicket.Event.keyCode(attrs.event)," + "evtType=attrs.event.type," + "ret=false;" + "if(evtType==='blur' || (evtType==='keyup' && (kc===27))) ret = true;" + "return ret;";
            AjaxCallListener ajaxCallListener = new AjaxCallListener();
            ajaxCallListener.onPrecondition(precondition);
            attributes.getAjaxCallListeners().add(ajaxCallListener);
        }
    });
    return editor;
}
Also used : AjaxRequestAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes) IModel(org.apache.wicket.model.IModel) TextArea(org.apache.wicket.markup.html.form.TextArea) AttributeModifier(org.apache.wicket.AttributeModifier) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 13 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxNewWindowNotifyingBehavior method updateAjaxAttributes.

/**
 * Overridden to add the current window name to the request.
 */
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    String parameter = "return {'" + PARAM_WINDOW_NAME + "': window.name}";
    attributes.getDynamicExtraParameters().add(parameter);
    if (boundName != null) {
        // already bound, send request only when changed
        attributes.getAjaxCallListeners().add(new AjaxCallListener() {

            @Override
            public CharSequence getPrecondition(Component component) {
                return String.format("return (window.name !== '%s');", boundName);
            }
        });
    }
}
Also used : Component(org.apache.wicket.Component) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Example 14 with AjaxCallListener

use of org.apache.wicket.ajax.attributes.AjaxCallListener in project wicket by apache.

the class AjaxPreventSubmitBehavior method updateAjaxAttributes.

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    Component component = getComponent();
    if (component instanceof TextField<?> == false) {
        attributes.setChildSelector("input");
    }
    AjaxCallListener listener = new AjaxCallListener();
    listener.onPrecondition("if (Wicket.Event.keyCode(attrs.event) === 13) {attrs.event.preventDefault();} return false;");
    attributes.getAjaxCallListeners().add(listener);
}
Also used : Component(org.apache.wicket.Component) AjaxCallListener(org.apache.wicket.ajax.attributes.AjaxCallListener)

Aggregations

AjaxCallListener (org.apache.wicket.ajax.attributes.AjaxCallListener)14 Component (org.apache.wicket.Component)9 AjaxRequestAttributes (org.apache.wicket.ajax.attributes.AjaxRequestAttributes)7 List (java.util.List)3 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)3 FormComponent (org.apache.wicket.markup.html.form.FormComponent)3 IModel (org.apache.wicket.model.IModel)3 ArrayList (java.util.ArrayList)2 IndicatorAjaxEventBehavior (org.apache.syncope.client.console.wicket.ajax.form.IndicatorAjaxEventBehavior)2 IAjaxCallListener (org.apache.wicket.ajax.attributes.IAjaxCallListener)2 TextField (com.googlecode.wicket.kendo.ui.form.TextField)1 BootstrapToggle (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggle)1 BootstrapToggleConfig (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig)1 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)1 AnnotationDetailEditorPanel.handleException (de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.handleException)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Transformer (org.apache.commons.collections4.Transformer)1