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());
}
});
}
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;
}
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);
}
});
}
}
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);
}
Aggregations