const created and moved
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/cbae4e0e Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/cbae4e0e Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/cbae4e0e Branch: refs/heads/master Commit: cbae4e0e97c277436b9b41430fd822d19c1d6275 Parents: f7d251c Author: Michael Mosmann <[email protected]> Authored: Wed Mar 6 23:37:18 2013 +0100 Committer: Michael Mosmann <[email protected]> Committed: Wed Mar 6 23:37:18 2013 +0100 ---------------------------------------------------------------------- .../wicket/ajax/AbstractDefaultAjaxBehavior.java | 85 ++++++----- .../ajax/attributes/AjaxRequestAttributes.java | 120 +++++++++++---- 2 files changed, 135 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/cbae4e0e/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java index 1673f10..a33b736 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AbstractDefaultAjaxBehavior.java @@ -55,6 +55,7 @@ import org.apache.wicket.util.time.Duration; */ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior { + private static final long serialVersionUID = 1L; /** reference to the default indicator gif file. */ @@ -133,13 +134,13 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior protected final AjaxRequestAttributes getAttributes() { AjaxRequestAttributes attributes = new AjaxRequestAttributes(); - WebApplication application = (WebApplication) getComponent().getApplication(); + WebApplication application = (WebApplication)getComponent().getApplication(); AjaxRequestTargetListenerCollection ajaxRequestTargetListeners = application.getAjaxRequestTargetListeners(); for (AjaxRequestTarget.IListener listener : ajaxRequestTargetListeners) { if (listener instanceof AjaxRequestTarget.AbstractListener) { - ((AjaxRequestTarget.AbstractListener) listener).updateAjaxAttributes(attributes); + ((AjaxRequestTarget.AbstractListener)listener).updateAjaxAttributes(attributes); } } updateAjaxAttributesBackwardCompatibility(attributes); @@ -218,40 +219,41 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior try { - attributesJson.put("u", getCallbackUrl()); + attributesJson.put(AjaxRequestAttributes.J_URL, getCallbackUrl()); Method method = attributes.getMethod(); if (Method.POST == method) { - attributesJson.put("m", method); + attributesJson.put(AjaxRequestAttributes.J_METHOD, method); } if (component instanceof Page == false) { String componentId = component.getMarkupId(); - attributesJson.put("c", componentId); + attributesJson.put(AjaxRequestAttributes.J_MARKUP_ID, componentId); } String formId = attributes.getFormId(); if (Strings.isEmpty(formId) == false) { - attributesJson.put("f", formId); + attributesJson.put(AjaxRequestAttributes.J_FORM_ID, formId); } if (attributes.isMultipart()) { - attributesJson.put("mp", true); + attributesJson.put(AjaxRequestAttributes.J_IS_MULTIPART, true); } String submittingComponentId = attributes.getSubmittingComponentName(); if (Strings.isEmpty(submittingComponentId) == false) { - attributesJson.put("sc", submittingComponentId); + attributesJson.put(AjaxRequestAttributes.J_SUBMITTING_COMPONENT_NAME, + submittingComponentId); } String indicatorId = findIndicatorId(); if (Strings.isEmpty(indicatorId) == false) { - attributesJson.put("i", indicatorId); + attributesJson.put(AjaxRequestAttributes.J_INDICATOR_ID, indicatorId); } for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners()) @@ -259,32 +261,34 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior if (ajaxCallListener != null) { CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component); - appendListenerHandler(beforeHandler, attributesJson, "bh", - BEFORE_HANDLER_FUNCTION_TEMPLATE); + appendListenerHandler(beforeHandler, attributesJson, + AjaxRequestAttributes.J_BEFORE_HANDLER, BEFORE_HANDLER_FUNCTION_TEMPLATE); CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component); - appendListenerHandler(beforeSendHandler, attributesJson, "bsh", + appendListenerHandler(beforeSendHandler, attributesJson, + AjaxRequestAttributes.J_BEFORE_SEND_HANDLER, BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE); CharSequence afterHandler = ajaxCallListener.getAfterHandler(component); - appendListenerHandler(afterHandler, attributesJson, "ah", - AFTER_HANDLER_FUNCTION_TEMPLATE); + appendListenerHandler(afterHandler, attributesJson, + AjaxRequestAttributes.J_AFTER_HANDLER, AFTER_HANDLER_FUNCTION_TEMPLATE); CharSequence successHandler = ajaxCallListener.getSuccessHandler(component); - appendListenerHandler(successHandler, attributesJson, "sh", - SUCCESS_HANDLER_FUNCTION_TEMPLATE); + appendListenerHandler(successHandler, attributesJson, + AjaxRequestAttributes.J_SUCCESS_HANDLER, SUCCESS_HANDLER_FUNCTION_TEMPLATE); CharSequence failureHandler = ajaxCallListener.getFailureHandler(component); - appendListenerHandler(failureHandler, attributesJson, "fh", - FAILURE_HANDLER_FUNCTION_TEMPLATE); + appendListenerHandler(failureHandler, attributesJson, + AjaxRequestAttributes.J_FAILURE_HANDLER, FAILURE_HANDLER_FUNCTION_TEMPLATE); CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component); - appendListenerHandler(completeHandler, attributesJson, "coh", + appendListenerHandler(completeHandler, attributesJson, + AjaxRequestAttributes.J_COMPLETE_HANDLER, COMPLETE_HANDLER_FUNCTION_TEMPLATE); CharSequence precondition = ajaxCallListener.getPrecondition(component); - appendListenerHandler(precondition, attributesJson, "pre", - PRECONDITION_FUNCTION_TEMPLATE); + appendListenerHandler(precondition, attributesJson, + AjaxRequestAttributes.J_PRECONDITION, PRECONDITION_FUNCTION_TEMPLATE); } } @@ -292,7 +296,7 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior if (extraParameters.length() > 0) { - attributesJson.put("ep", extraParameters); + attributesJson.put(AjaxRequestAttributes.J_EXTRA_PARAMETERS, extraParameters); } List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters(); @@ -303,68 +307,73 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE, dynamicExtraParameter); JsonFunction function = new JsonFunction(func); - attributesJson.append("dep", function); + attributesJson.append(AjaxRequestAttributes.J_DYNAMIC_PARAMETER_FUNCTION, + function); } } if (attributes.isAsynchronous() == false) { - attributesJson.put("async", false); + attributesJson.put(AjaxRequestAttributes.J_IS_ASYNC, false); } String[] eventNames = attributes.getEventNames(); if (eventNames.length == 1) { - attributesJson.put("e", eventNames[0]); + attributesJson.put(AjaxRequestAttributes.J_EVENT_NAME, eventNames[0]); } else { for (String eventName : eventNames) { - attributesJson.append("e", eventName); + attributesJson.append(AjaxRequestAttributes.J_EVENT_NAME, eventName); } } AjaxChannel channel = attributes.getChannel(); if (channel != null) { - attributesJson.put("ch", channel); + attributesJson.put(AjaxRequestAttributes.J_CHANNEL, channel); } if (attributes.isAllowDefault()) { - attributesJson.put("ad", true); + attributesJson.put(AjaxRequestAttributes.J_IS_ALLOW_DEFAULT, true); } Duration requestTimeout = attributes.getRequestTimeout(); if (requestTimeout != null) { - attributesJson.put("rt", requestTimeout.getMilliseconds()); + attributesJson.put(AjaxRequestAttributes.J_REQUEST_TIMEOUT, + requestTimeout.getMilliseconds()); } boolean wicketAjaxResponse = attributes.isWicketAjaxResponse(); if (wicketAjaxResponse == false) { - attributesJson.put("wr", false); + attributesJson.put(AjaxRequestAttributes.J_IS_WICKET_AJAX_RESPONSE, false); } String dataType = attributes.getDataType(); if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false) { - attributesJson.put("dt", dataType); + attributesJson.put(AjaxRequestAttributes.J_DATATYPE, dataType); } ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings(); if (throttlingSettings != null) { JSONObject throttlingSettingsJson = new JSONObject(); - throttlingSettingsJson.put("id", throttlingSettings.getId()); - throttlingSettingsJson.put("d", throttlingSettings.getDelay().getMilliseconds()); + throttlingSettingsJson.put(AjaxRequestAttributes.J_THROTTLING_ID, + throttlingSettings.getId()); + throttlingSettingsJson.put(AjaxRequestAttributes.J_THROTTLING_DELAY, + throttlingSettings.getDelay().getMilliseconds()); if (throttlingSettings.getPostponeTimerOnUpdate()) { - throttlingSettingsJson.put("p", true); + throttlingSettingsJson.put( + AjaxRequestAttributes.J_THROTTLING_POSTPONE_ON_UPDATE, true); } - attributesJson.put("tr", throttlingSettingsJson); + attributesJson.put(AjaxRequestAttributes.J_THROTTLING, throttlingSettingsJson); } postprocessConfiguration(attributesJson, component); @@ -510,9 +519,11 @@ public abstract class AbstractDefaultAjaxBehavior extends AbstractAjaxBehavior } sb.append("};\n"); if (attributes.getExtraParameters().isEmpty()) - sb.append("attrs.ep = params;\n"); + sb.append("attrs." + AjaxRequestAttributes.J_EXTRA_PARAMETERS + " = params;\n"); else - sb.append("attrs.ep = Wicket.merge(attrs.ep, params);\n"); + sb.append("attrs." + AjaxRequestAttributes.J_EXTRA_PARAMETERS + + " = Wicket.merge(attrs." + AjaxRequestAttributes.J_EXTRA_PARAMETERS + + ", params);\n"); sb.append("Wicket.Ajax.ajax(attrs);\n"); return sb; } http://git-wip-us.apache.org/repos/asf/wicket/blob/cbae4e0e/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java index 54cb67d..a8a1e6b 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/attributes/AjaxRequestAttributes.java @@ -32,6 +32,60 @@ import org.apache.wicket.util.time.Duration; */ public final class AjaxRequestAttributes { + public static final String J_THROTTLING = "tr"; + + public static final String J_THROTTLING_POSTPONE_ON_UPDATE = "p"; + + public static final String J_THROTTLING_DELAY = "d"; + + public static final String J_THROTTLING_ID = "id"; + + public static final String J_DATATYPE = "dt"; + + public static final String J_IS_WICKET_AJAX_RESPONSE = "wr"; + + public static final String J_REQUEST_TIMEOUT = "rt"; + + public static final String J_IS_ALLOW_DEFAULT = "ad"; + + public static final String J_CHANNEL = "ch"; + + public static final String J_EVENT_NAME = "e"; + + public static final String J_IS_ASYNC = "async"; + + public static final String J_DYNAMIC_PARAMETER_FUNCTION = "dep"; + + public static final String J_EXTRA_PARAMETERS = "ep"; + + public static final String J_PRECONDITION = "pre"; + + public static final String J_COMPLETE_HANDLER = "coh"; + + public static final String J_FAILURE_HANDLER = "fh"; + + public static final String J_SUCCESS_HANDLER = "sh"; + + public static final String J_AFTER_HANDLER = "ah"; + + public static final String J_BEFORE_SEND_HANDLER = "bsh"; + + public static final String J_BEFORE_HANDLER = "bh"; + + public static final String J_INDICATOR_ID = "i"; + + public static final String J_SUBMITTING_COMPONENT_NAME = "sc"; + + public static final String J_IS_MULTIPART = "mp"; + + public static final String J_FORM_ID = "f"; + + public static final String J_MARKUP_ID = "c"; + + public static final String J_METHOD = "m"; + + public static final String J_URL = "u"; + /** * The method to be used when submitting a form @@ -98,9 +152,8 @@ public final class AjaxRequestAttributes private boolean async = true; /** - * The settings to use if the Ajax call should be throttled. - * Throttled behaviors only execute once within the given delay - * even though they are triggered multiple times. + * The settings to use if the Ajax call should be throttled. Throttled behaviors only execute + * once within the given delay even though they are triggered multiple times. * <p> * For example, this is useful when attaching a behavior to the keypress event. It is not * desirable to have an ajax call made every time the user types so we throttle that call to a @@ -159,7 +212,7 @@ public final class AjaxRequestAttributes * the URL parameters are longer than maximal URL length. * * @param method - * the type of the Ajax request + * the type of the Ajax request * @return {@code this} object for chaining */ public AjaxRequestAttributes setMethod(final Method method) @@ -195,8 +248,8 @@ public final class AjaxRequestAttributes } /** - * @return a list of {@link IAjaxCallListener}s which will be notified during the - * the execution of the Ajax call. + * @return a list of {@link IAjaxCallListener}s which will be notified during the the execution + * of the Ajax call. */ public List<IAjaxCallListener> getAjaxCallListeners() { @@ -209,9 +262,9 @@ public final class AjaxRequestAttributes /** * Map that contains additional (static) URL parameters. These will be appended to the request - * URL. If you need more than one value for a key then use a java.util.List or an Object[] as - * a value of that key. - * + * URL. If you need more than one value for a key then use a java.util.List or an Object[] as a + * value of that key. + * * @return a map with additional URL arguments * @see #getDynamicExtraParameters() */ @@ -226,32 +279,33 @@ public final class AjaxRequestAttributes /** * Array of JavaScript functions that produce additional URL arguments. - * - * <p>If there are no multivalued parameters then the function can return a - * simple JavaScript object. Example: - * + * + * <p> + * If there are no multivalued parameters then the function can return a simple JavaScript + * object. Example: + * * <pre> * return { * 'param1': document.body.tagName, * 'param2': calculateParam2() * } * </pre> - * + * * </p> - * <p>If there are multivalued parameters then an array of objects may be used. - * Example: - * + * <p> + * If there are multivalued parameters then an array of objects may be used. Example: + * * <pre> * return [ * { name: 'param1', value: document.body.tagName }, * { name: 'param1', value: calculateSecondValueForParam1() }, * { name: 'param2', value: calculateParam2() } * ] - * + * * </pre> - * + * * </p> - * + * * @return a list of functions that produce additional URL arguments. * @see #getExtraParameters() */ @@ -269,11 +323,10 @@ public final class AjaxRequestAttributes * handler to be invoked. For example if the behavior is attached to a link and * {@link #isAllowDefault()} returns <code>false</code> (which is default value), the link's URL * will not be followed. If the Ajax behavior is attached to a checkbox or a radio button then - * the default behavior should be allowed to actually check the box or radio button, i.e. - * this method should return <code>true</code>. + * the default behavior should be allowed to actually check the box or radio button, i.e. this + * method should return <code>true</code>. * - * @return {@code true} if the default event handler should be invoked, {@code false} - * otherwise. + * @return {@code true} if the default event handler should be invoked, {@code false} otherwise. */ public boolean isAllowDefault() { @@ -325,8 +378,8 @@ public final class AjaxRequestAttributes /** * @param channel - * the Ajax channel to use. Pass {@code null} to use the default channel - * with name <em>0</em> and queueing type. + * the Ajax channel to use. Pass {@code null} to use the default channel with name + * <em>0</em> and queueing type. * @return {@code this} object for chaining */ public AjaxRequestAttributes setChannel(final AjaxChannel channel) @@ -394,8 +447,8 @@ public final class AjaxRequestAttributes } /** - * @return a flag indicating whether the Ajax response should be processed by - * Wicket (i.e. to replace components, execute scripts, etc.). Default: {@code true}. + * @return a flag indicating whether the Ajax response should be processed by Wicket (i.e. to + * replace components, execute scripts, etc.). Default: {@code true}. */ public boolean isWicketAjaxResponse() { @@ -404,8 +457,8 @@ public final class AjaxRequestAttributes /** * @param wicketAjaxResponse - * a flag indicating whether the Ajax response should be processed by - * Wicket (i.e. to replace components, execute scripts, etc.). + * a flag indicating whether the Ajax response should be processed by Wicket (i.e. to + * replace components, execute scripts, etc.). * @return {@code this} object for chaining */ public AjaxRequestAttributes setWicketAjaxResponse(final boolean wicketAjaxResponse) @@ -417,7 +470,7 @@ public final class AjaxRequestAttributes /** * Returns the type of the data in the Ajax response. For example: 'xml', 'json', 'html', etc. * See the documentation of jQuery.ajax() method for more information. - * + * * @return the type of the data in the Ajax response. */ public String getDataType() @@ -427,7 +480,7 @@ public final class AjaxRequestAttributes /** * @param dataType - * the type of the data in the Ajax response. + * the type of the data in the Ajax response. * @return {@code this} object for chaining */ public AjaxRequestAttributes setDataType(final String dataType) @@ -446,7 +499,8 @@ public final class AjaxRequestAttributes /** * @param throttlingSettings - * the settings to use when throttling is needed. Pass {@code null} to disable throttling. + * the settings to use when throttling is needed. Pass {@code null} to disable + * throttling. * @return {@code this} object for chaining */ public AjaxRequestAttributes setThrottlingSettings(ThrottlingSettings throttlingSettings)
