Package org.apache.wicket.ajax.json

Examples of org.apache.wicket.ajax.json.JSONObject


   * @return the attributes as string in JSON format
   */
  protected final CharSequence renderAjaxAttributes(final Component component,
    AjaxRequestAttributes attributes)
  {
    JSONObject attributesJson = new JSONObject();

    try
    {
      attributesJson.put("u", getCallbackUrl());
      Method method = attributes.getMethod();
      if (Method.POST == method)
      {
        attributesJson.put("m", method);
      }

      if (component instanceof Page == false)
      {
        String componentId = component.getMarkupId();
        attributesJson.put("c", componentId);
      }

      String formId = attributes.getFormId();
      if (Strings.isEmpty(formId) == false)
      {
        attributesJson.put("f", formId);
      }

      if (attributes.isMultipart())
      {
        attributesJson.put("mp", true);
      }

      String submittingComponentId = attributes.getSubmittingComponentName();
      if (Strings.isEmpty(submittingComponentId) == false)
      {
        attributesJson.put("sc", submittingComponentId);
      }

      String indicatorId = findIndicatorId();
      if (Strings.isEmpty(indicatorId) == false)
      {
        attributesJson.put("i", indicatorId);
      }

      for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners())
      {
        if (ajaxCallListener != null)
        {
          CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
          appendListenerHandler(beforeHandler, attributesJson, "bh",
            BEFORE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component);
          appendListenerHandler(beforeSendHandler, attributesJson, "bsh",
            BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          appendListenerHandler(afterHandler, attributesJson, "ah",
            AFTER_HANDLER_FUNCTION_TEMPLATE);

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          appendListenerHandler(successHandler, attributesJson, "sh",
            SUCCESS_HANDLER_FUNCTION_TEMPLATE);

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          appendListenerHandler(failureHandler, attributesJson, "fh",
            FAILURE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          appendListenerHandler(completeHandler, attributesJson, "coh",
            COMPLETE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          appendListenerHandler(precondition, attributesJson, "pre",
            PRECONDITION_FUNCTION_TEMPLATE);
        }
      }

      JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters());

      if (extraParameters.length() > 0)
      {
        attributesJson.put("ep", extraParameters);
      }

      List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
      if (dynamicExtraParameters != null)
      {
        for (CharSequence dynamicExtraParameter : dynamicExtraParameters)
        {
          String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE,
            dynamicExtraParameter);
          JsonFunction function = new JsonFunction(func);
          attributesJson.append("dep", function);
        }
      }

      if (attributes.isAsynchronous() == false)
      {
        attributesJson.put("async", false);
      }

      String[] eventNames = attributes.getEventNames();
      if (eventNames.length == 1)
      {
        attributesJson.put("e", eventNames[0]);
      }
      else
      {
        for (String eventName : eventNames)
        {
          attributesJson.append("e", eventName);
        }
      }

      AjaxChannel channel = attributes.getChannel();
      if (channel != null)
      {
        attributesJson.put("ch", channel);
      }

      if (attributes.isAllowDefault())
      {
        attributesJson.put("ad", true);
      }

      Duration requestTimeout = attributes.getRequestTimeout();
      if (requestTimeout != null)
      {
        attributesJson.put("rt", requestTimeout.getMilliseconds());
      }

      boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
      if (wicketAjaxResponse == false)
      {
        attributesJson.put("wr", false);
      }

      String dataType = attributes.getDataType();
      if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false)
      {
        attributesJson.put("dt", dataType);
      }

      ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
      if (throttlingSettings != null)
      {
        JSONObject throttlingSettingsJson = new JSONObject();
        throttlingSettingsJson.put("id", throttlingSettings.getId());
        throttlingSettingsJson.put("d", throttlingSettings.getDelay().getMilliseconds());
        if (throttlingSettings.getPostponeTimerOnUpdate())
        {
          throttlingSettingsJson.put("p", true);
        }
        attributesJson.put("tr", throttlingSettingsJson);
      }

      postprocessConfiguration(attributesJson, component);
View Full Code Here


   * @return the attributes as string in JSON format
   */
  protected final CharSequence renderAjaxAttributes(final Component component,
    AjaxRequestAttributes attributes)
  {
    JSONObject attributesJson = new JSONObject();

    try
    {
      attributesJson.put("u", getCallbackUrl());
      Method method = attributes.getMethod();
      if (Method.POST == method)
      {
        attributesJson.put("m", method);
      }

      if (component instanceof Page == false)
      {
        String componentId = component.getMarkupId();
        attributesJson.put("c", componentId);
      }

      String formId = attributes.getFormId();
      if (Strings.isEmpty(formId) == false)
      {
        attributesJson.put("f", formId);
      }

      if (attributes.isMultipart())
      {
        attributesJson.put("mp", true);
      }

      String submittingComponentId = attributes.getSubmittingComponentName();
      if (Strings.isEmpty(submittingComponentId) == false)
      {
        attributesJson.put("sc", submittingComponentId);
      }

      String indicatorId = findIndicatorId();
      if (Strings.isEmpty(indicatorId) == false)
      {
        attributesJson.put("i", indicatorId);
      }

      for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners())
      {
        if (ajaxCallListener != null)
        {
          CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
          appendListenerHandler(beforeHandler, attributesJson, "bh", BEFORE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component);
          appendListenerHandler(beforeSendHandler, attributesJson, "bsh", BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          appendListenerHandler(afterHandler, attributesJson, "ah", AFTER_HANDLER_FUNCTION_TEMPLATE);

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          appendListenerHandler(successHandler, attributesJson, "sh", SUCCESS_HANDLER_FUNCTION_TEMPLATE);

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          appendListenerHandler(failureHandler, attributesJson, "fh", FAILURE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          appendListenerHandler(completeHandler, attributesJson, "coh", COMPLETE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          appendListenerHandler(precondition, attributesJson, "pre", PRECONDITION_FUNCTION_TEMPLATE);
        }
      }

      JSONObject extraParameters = new JSONObject();
      Iterator<Entry<String, Object>> itor = attributes.getExtraParameters()
        .entrySet()
        .iterator();
      while (itor.hasNext())
      {
        Entry<String, Object> entry = itor.next();
        String name = entry.getKey();
        Object value = entry.getValue();
        extraParameters.accumulate(name, value);
      }
      if (extraParameters.length() > 0)
      {
        attributesJson.put("ep", extraParameters);
      }

      List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
      if (dynamicExtraParameters != null)
      {
        for (CharSequence dynamicExtraParameter : dynamicExtraParameters)
        {
          String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE, dynamicExtraParameter);
          JsonFunction function = new JsonFunction(func);
          attributesJson.append("dep", function);
        }
      }

      if (attributes.isAsynchronous() == false)
      {
        attributesJson.put("async", false);
      }

      String[] eventNames = attributes.getEventNames();
      if (eventNames.length == 1)
      {
        attributesJson.put("e", eventNames[0]);
      }
      else
      {
        for (String eventName : eventNames)
        {
          attributesJson.append("e", eventName);
        }
      }

      AjaxChannel channel = attributes.getChannel();
      if (channel != null)
      {
        attributesJson.put("ch", channel);
      }

      if (attributes.isAllowDefault())
      {
        attributesJson.put("ad", true);
      }

      Duration requestTimeout = attributes.getRequestTimeout();
      if (requestTimeout != null)
      {
        attributesJson.put("rt", requestTimeout.getMilliseconds());
      }

      boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
      if (wicketAjaxResponse == false)
      {
        attributesJson.put("wr", false);
      }

      String dataType = attributes.getDataType();
      if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false)
      {
        attributesJson.put("dt", dataType);
      }

      ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
      if (throttlingSettings != null)
      {
        JSONObject throttlingSettingsJson = new JSONObject();
        throttlingSettingsJson.put("id", throttlingSettings.getId());
        throttlingSettingsJson.put("d", throttlingSettings.getDelay().getMilliseconds());
        if (throttlingSettings.getPostponeTimerOnUpdate())
        {
          throttlingSettingsJson.put("p", true);
        }
        attributesJson.put("tr", throttlingSettingsJson);
      }

      postprocessConfiguration(attributesJson, component);
View Full Code Here

    try
    {
      CoreLibrariesContributor.contributeAjax(component.getApplication(), response);

      response.render(JavaScriptHeaderItem.forReference(JQueryWicketAtmosphereResourceReference.get()));
      JSONObject options = new JSONObject();
      options.put("url",
        component.urlFor(this, IResourceListener.INTERFACE, new PageParameters())
          .toString());
      response.render(OnDomReadyHeaderItem.forScript("$('#" + component.getMarkupId() +
        "').wicketAtmosphere(" + options.toString() + ")"));
    }
    catch (JSONException e)
    {
      throw new WicketRuntimeException(e);
    }
View Full Code Here

            protected String generateJsonResponse(ResourceResponse resourceResponse, ServletWebRequest webRequest, List<FileItem> files) {
                JSONArray json = new JSONArray();

                for (FileItem fileItem : files)
                {
                    JSONObject fileJson = new JSONObject();

                    try {
                        fileJson.put("name", fileItem.getName());
                        fileJson.put("url", getViewUrl(fileItem));
                        fileJson.put("thumbnail_url", getViewUrl(fileItem));
                        fileJson.put("size", fileItem.getSize());
                        fileJson.put("delete_type", "POST");
                        fileJson.put("delete_url", getDeleteUrl(fileItem));
                    } catch (JSONException e) {
                        try {
                            fileJson.put("error", e.getMessage());
                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                    }
View Full Code Here

   * @return the attributes as string in JSON format
   */
  protected final CharSequence renderAjaxAttributes(final Component component,
    AjaxRequestAttributes attributes)
  {
    JSONObject attributesJson = new JSONObject();

    try
    {
      attributesJson.put(AjaxAttributeName.URL.jsonName(), getCallbackUrl());
      Method method = attributes.getMethod();
      if (Method.POST == method)
      {
        attributesJson.put(AjaxAttributeName.METHOD.jsonName(), method);
      }

      if (component instanceof Page == false)
      {
        String componentId = component.getMarkupId();
        attributesJson.put(AjaxAttributeName.MARKUP_ID.jsonName(), componentId);
      }

      String formId = attributes.getFormId();
      if (Strings.isEmpty(formId) == false)
      {
        attributesJson.put(AjaxAttributeName.FORM_ID.jsonName(), formId);
      }

      if (attributes.isMultipart())
      {
        attributesJson.put(AjaxAttributeName.IS_MULTIPART.jsonName(), true);
      }

      String submittingComponentId = attributes.getSubmittingComponentName();
      if (Strings.isEmpty(submittingComponentId) == false)
      {
        attributesJson.put(AjaxAttributeName.SUBMITTING_COMPONENT_NAME.jsonName(),
          submittingComponentId);
      }

      CharSequence childSelector = attributes.getChildSelector();
      if (Strings.isEmpty(childSelector) == false)
      {
        attributesJson.put(AjaxAttributeName.CHILD_SELECTOR.jsonName(),
            childSelector);
      }

      String indicatorId = findIndicatorId();
      if (Strings.isEmpty(indicatorId) == false)
      {
        attributesJson.put(AjaxAttributeName.INDICATOR_ID.jsonName(), indicatorId);
      }

      for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners())
      {
        if (ajaxCallListener != null)
        {
          CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
          appendListenerHandler(beforeHandler, attributesJson,
            AjaxAttributeName.BEFORE_HANDLER.jsonName(),
            BEFORE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence beforeSendHandler = ajaxCallListener
            .getBeforeSendHandler(component);
          appendListenerHandler(beforeSendHandler, attributesJson,
            AjaxAttributeName.BEFORE_SEND_HANDLER.jsonName(),
            BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          appendListenerHandler(afterHandler, attributesJson,
            AjaxAttributeName.AFTER_HANDLER.jsonName(), AFTER_HANDLER_FUNCTION_TEMPLATE);

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          appendListenerHandler(successHandler, attributesJson,
            AjaxAttributeName.SUCCESS_HANDLER.jsonName(),
            SUCCESS_HANDLER_FUNCTION_TEMPLATE);

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          appendListenerHandler(failureHandler, attributesJson,
            AjaxAttributeName.FAILURE_HANDLER.jsonName(),
            FAILURE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          appendListenerHandler(completeHandler, attributesJson,
            AjaxAttributeName.COMPLETE_HANDLER.jsonName(),
            COMPLETE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          appendListenerHandler(precondition, attributesJson,
            AjaxAttributeName.PRECONDITION.jsonName(), PRECONDITION_FUNCTION_TEMPLATE);
        }
      }

      JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters());

      if (extraParameters.length() > 0)
      {
        attributesJson.put(AjaxAttributeName.EXTRA_PARAMETERS.jsonName(), extraParameters);
      }

      List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
      if (dynamicExtraParameters != null)
      {
        for (CharSequence dynamicExtraParameter : dynamicExtraParameters)
        {
          String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE,
            dynamicExtraParameter);
          JsonFunction function = new JsonFunction(func);
          attributesJson.append(AjaxAttributeName.DYNAMIC_PARAMETER_FUNCTION.jsonName(),
            function);
        }
      }

      if (attributes.isAsynchronous() == false)
      {
        attributesJson.put(AjaxAttributeName.IS_ASYNC.jsonName(), false);
      }

      String[] eventNames = attributes.getEventNames();
      if (eventNames.length == 1)
      {
        attributesJson.put(AjaxAttributeName.EVENT_NAME.jsonName(), eventNames[0]);
      }
      else
      {
        for (String eventName : eventNames)
        {
          attributesJson.append(AjaxAttributeName.EVENT_NAME.jsonName(), eventName);
        }
      }

      AjaxChannel channel = attributes.getChannel();
      if (channel != null && channel.equals(AjaxChannel.DEFAULT) == false)
      {
        attributesJson.put(AjaxAttributeName.CHANNEL.jsonName(), channel);
      }

      if (attributes.isPreventDefault())
      {
        attributesJson.put(AjaxAttributeName.IS_PREVENT_DEFAULT.jsonName(), true);
      }

      if (AjaxRequestAttributes.EventPropagation.STOP
        .equals(attributes.getEventPropagation()))
      {
        attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stop");
      }
      else if (AjaxRequestAttributes.EventPropagation.STOP_IMMEDIATE.equals(attributes
        .getEventPropagation()))
      {
        attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stopImmediate");
      }

      Duration requestTimeout = attributes.getRequestTimeout();
      if (requestTimeout != null)
      {
        attributesJson.put(AjaxAttributeName.REQUEST_TIMEOUT.jsonName(),
          requestTimeout.getMilliseconds());
      }

      boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
      if (wicketAjaxResponse == false)
      {
        attributesJson.put(AjaxAttributeName.IS_WICKET_AJAX_RESPONSE.jsonName(), false);
      }

      String dataType = attributes.getDataType();
      if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false)
      {
        attributesJson.put(AjaxAttributeName.DATATYPE.jsonName(), dataType);
      }

      ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
      if (throttlingSettings != null)
      {
        JSONObject throttlingSettingsJson = new JSONObject();
        String throttleId = throttlingSettings.getId();
        if (throttleId == null)
        {
          throttleId = component.getMarkupId();
        }
        throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_ID.jsonName(), throttleId);
        throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_DELAY.jsonName(),
          throttlingSettings.getDelay().getMilliseconds());
        if (throttlingSettings.getPostponeTimerOnUpdate())
        {
          throttlingSettingsJson.put(
            AjaxAttributeName.THROTTLING_POSTPONE_ON_UPDATE.jsonName(), true);
        }
        attributesJson.put(AjaxAttributeName.THROTTLING.jsonName(), throttlingSettingsJson);
      }

View Full Code Here

   * @return the attributes as string in JSON format
   */
  protected final CharSequence renderAjaxAttributes(final Component component,
    AjaxRequestAttributes attributes)
  {
    JSONObject attributesJson = new JSONObject();

    try
    {
      attributesJson.put("u", getCallbackUrl());
      Method method = attributes.getMethod();
      if (Method.POST == method)
      {
        attributesJson.put("m", method);
      }

      if (component instanceof Page == false)
      {
        String componentId = component.getMarkupId();
        attributesJson.put("c", componentId);
      }

      String formId = attributes.getFormId();
      if (Strings.isEmpty(formId) == false)
      {
        attributesJson.put("f", formId);
      }

      if (attributes.isMultipart())
      {
        attributesJson.put("mp", true);
      }

      String submittingComponentId = attributes.getSubmittingComponentName();
      if (Strings.isEmpty(submittingComponentId) == false)
      {
        attributesJson.put("sc", submittingComponentId);
      }

      String indicatorId = findIndicatorId();
      if (Strings.isEmpty(indicatorId) == false)
      {
        attributesJson.put("i", indicatorId);
      }

      for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners())
      {
        if (ajaxCallListener != null)
        {
          CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
          if (Strings.isEmpty(beforeHandler) == false)
          {
            attributesJson.append("bh", beforeHandler);
          }

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          if (Strings.isEmpty(afterHandler) == false)
          {
            attributesJson.append("ah", afterHandler);
          }

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          if (Strings.isEmpty(successHandler) == false)
          {
            attributesJson.append("sh", successHandler);
          }

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          if (Strings.isEmpty(failureHandler) == false)
          {
            attributesJson.append("fh", failureHandler);
          }

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          if (Strings.isEmpty(completeHandler) == false)
          {
            attributesJson.append("coh", completeHandler);
          }

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          if (Strings.isEmpty(precondition) == false)
          {
            attributesJson.append("pre", precondition);
          }
        }
      }

      JSONObject extraParameters = new JSONObject();
      Iterator<Entry<String, Object>> itor = attributes.getExtraParameters()
        .entrySet()
        .iterator();
      while (itor.hasNext())
      {
        Entry<String, Object> entry = itor.next();
        String name = entry.getKey();
        Object value = entry.getValue();
        extraParameters.accumulate(name, value);
      }
      if (extraParameters.length() > 0)
      {
        attributesJson.put("ep", extraParameters);
      }

      List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
      if (dynamicExtraParameters != null)
      {
        for (CharSequence dynamicExtraParameter : dynamicExtraParameters)
        {
          attributesJson.append("dep", dynamicExtraParameter);
        }
      }

      if (attributes.isAsynchronous() == false)
      {
        attributesJson.put("async", false);
      }

      String[] eventNames = attributes.getEventNames();
      if (eventNames.length == 1)
      {
        attributesJson.put("e", eventNames[0]);
      }
      else
      {
        for (String eventName : eventNames)
        {
          attributesJson.append("e", eventName);
        }
      }

      AjaxChannel channel = attributes.getChannel();
      if (channel != null)
      {
        attributesJson.put("ch", channel);
      }

      if (attributes.isAllowDefault())
      {
        attributesJson.put("ad", true);
      }

      Duration requestTimeout = attributes.getRequestTimeout();
      if (requestTimeout != null)
      {
        attributesJson.put("rt", requestTimeout.getMilliseconds());
      }

      boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
      if (wicketAjaxResponse == false)
      {
        attributesJson.put("wr", false);
      }

      String dataType = attributes.getDataType();
      if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false)
      {
        attributesJson.put("dt", dataType);
      }

      ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
      if (throttlingSettings != null)
      {
        JSONObject throttlingSettingsJson = new JSONObject();
        throttlingSettingsJson.put("id", throttlingSettings.getId());
        throttlingSettingsJson.put("d", throttlingSettings.getDelay().getMilliseconds());
        if (throttlingSettings.getPostponeTimerOnUpdate())
        {
          throttlingSettingsJson.put("p", true);
        }
        attributesJson.put("tr", throttlingSettingsJson);
      }

      postprocessConfiguration(attributesJson, component);
View Full Code Here

   * @return the attributes as string in JSON format
   */
  protected final CharSequence renderAjaxAttributes(final Component component,
    AjaxRequestAttributes attributes)
  {
    JSONObject attributesJson = new JSONObject();

    try
    {
      attributesJson.put(AjaxAttributeName.URL.jsonName(), getCallbackUrl());
      Method method = attributes.getMethod();
      if (Method.POST == method)
      {
        attributesJson.put(AjaxAttributeName.METHOD.jsonName(), method);
      }

      if (component instanceof Page == false)
      {
        String componentId = component.getMarkupId();
        attributesJson.put(AjaxAttributeName.MARKUP_ID.jsonName(), componentId);
      }

      String formId = attributes.getFormId();
      if (Strings.isEmpty(formId) == false)
      {
        attributesJson.put(AjaxAttributeName.FORM_ID.jsonName(), formId);
      }

      if (attributes.isMultipart())
      {
        attributesJson.put(AjaxAttributeName.IS_MULTIPART.jsonName(), true);
      }

      String submittingComponentId = attributes.getSubmittingComponentName();
      if (Strings.isEmpty(submittingComponentId) == false)
      {
        attributesJson.put(AjaxAttributeName.SUBMITTING_COMPONENT_NAME.jsonName(),
          submittingComponentId);
      }

      CharSequence childSelector = attributes.getChildSelector();
      if (Strings.isEmpty(childSelector) == false)
      {
        attributesJson.put(AjaxAttributeName.CHILD_SELECTOR.jsonName(),
            childSelector);
      }

      String indicatorId = findIndicatorId();
      if (Strings.isEmpty(indicatorId) == false)
      {
        attributesJson.put(AjaxAttributeName.INDICATOR_ID.jsonName(), indicatorId);
      }

      for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners())
      {
        if (ajaxCallListener != null)
        {
          CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
          appendListenerHandler(beforeHandler, attributesJson,
            AjaxAttributeName.BEFORE_HANDLER.jsonName(),
            BEFORE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component);
          appendListenerHandler(beforeSendHandler, attributesJson,
            AjaxAttributeName.BEFORE_SEND_HANDLER.jsonName(),
            BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          appendListenerHandler(afterHandler, attributesJson,
            AjaxAttributeName.AFTER_HANDLER.jsonName(), AFTER_HANDLER_FUNCTION_TEMPLATE);

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          appendListenerHandler(successHandler, attributesJson,
            AjaxAttributeName.SUCCESS_HANDLER.jsonName(),
            SUCCESS_HANDLER_FUNCTION_TEMPLATE);

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          appendListenerHandler(failureHandler, attributesJson,
            AjaxAttributeName.FAILURE_HANDLER.jsonName(),
            FAILURE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          appendListenerHandler(completeHandler, attributesJson,
            AjaxAttributeName.COMPLETE_HANDLER.jsonName(),
            COMPLETE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          appendListenerHandler(precondition, attributesJson,
            AjaxAttributeName.PRECONDITION.jsonName(), PRECONDITION_FUNCTION_TEMPLATE);
        }
      }

      JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters());

      if (extraParameters.length() > 0)
      {
        attributesJson.put(AjaxAttributeName.EXTRA_PARAMETERS.jsonName(), extraParameters);
      }

      List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
      if (dynamicExtraParameters != null)
      {
        for (CharSequence dynamicExtraParameter : dynamicExtraParameters)
        {
          String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE,
            dynamicExtraParameter);
          JsonFunction function = new JsonFunction(func);
          attributesJson.append(AjaxAttributeName.DYNAMIC_PARAMETER_FUNCTION.jsonName(),
            function);
        }
      }

      if (attributes.isAsynchronous() == false)
      {
        attributesJson.put(AjaxAttributeName.IS_ASYNC.jsonName(), false);
      }

      String[] eventNames = attributes.getEventNames();
      if (eventNames.length == 1)
      {
        attributesJson.put(AjaxAttributeName.EVENT_NAME.jsonName(), eventNames[0]);
      }
      else
      {
        for (String eventName : eventNames)
        {
          attributesJson.append(AjaxAttributeName.EVENT_NAME.jsonName(), eventName);
        }
      }

      AjaxChannel channel = attributes.getChannel();
      if (channel != null && channel.equals(AjaxChannel.DEFAULT) == false)
      {
        attributesJson.put(AjaxAttributeName.CHANNEL.jsonName(), channel);
      }

      if (attributes.isAllowDefault())
      {
        attributesJson.put(AjaxAttributeName.IS_ALLOW_DEFAULT.jsonName(), true);
      }

      if (AjaxRequestAttributes.EventPropagation.BUBBLE.equals(attributes.getEventPropagation()))
      {
        attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "bubble");
      }
      else if (AjaxRequestAttributes.EventPropagation.STOP_IMMEDIATE.equals(attributes.getEventPropagation()))
      {
        attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stopImmediate");
      }

      Duration requestTimeout = attributes.getRequestTimeout();
      if (requestTimeout != null)
      {
        attributesJson.put(AjaxAttributeName.REQUEST_TIMEOUT.jsonName(),
          requestTimeout.getMilliseconds());
      }

      boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
      if (wicketAjaxResponse == false)
      {
        attributesJson.put(AjaxAttributeName.IS_WICKET_AJAX_RESPONSE.jsonName(), false);
      }

      String dataType = attributes.getDataType();
      if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false)
      {
        attributesJson.put(AjaxAttributeName.DATATYPE.jsonName(), dataType);
      }

      ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
      if (throttlingSettings != null)
      {
        JSONObject throttlingSettingsJson = new JSONObject();
        throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_ID.jsonName(),
          throttlingSettings.getId());
        throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_DELAY.jsonName(),
          throttlingSettings.getDelay().getMilliseconds());
        if (throttlingSettings.getPostponeTimerOnUpdate())
        {
          throttlingSettingsJson.put(
            AjaxAttributeName.THROTTLING_POSTPONE_ON_UPDATE.jsonName(), true);
        }
        attributesJson.put(AjaxAttributeName.THROTTLING.jsonName(), throttlingSettingsJson);
      }

View Full Code Here

    try
    {
      CoreLibrariesContributor.contributeAjax(component.getApplication(), response);

      response.render(JavaScriptHeaderItem.forReference(JQueryWicketAtmosphereResourceReference.get()));
      JSONObject options = new JSONObject();
      options.put("url",
        component.urlFor(this, IResourceListener.INTERFACE, new PageParameters())
          .toString());
      response.render(OnDomReadyHeaderItem.forScript("$('#" + component.getMarkupId() +
        "').wicketAtmosphere(" + options.toString() + ")"));
    }
    catch (JSONException e)
    {
      throw new WicketRuntimeException(e);
    }
View Full Code Here

   * @return the attributes as string in JSON format
   */
  protected final CharSequence renderAjaxAttributes(final Component component,
    AjaxRequestAttributes attributes)
  {
    JSONObject attributesJson = new JSONObject();

    try
    {
      attributesJson.put(AjaxAttributeName.URL.jsonName(), getCallbackUrl());
      Method method = attributes.getMethod();
      if (Method.POST == method)
      {
        attributesJson.put(AjaxAttributeName.METHOD.jsonName(), method);
      }

      if (component instanceof Page == false)
      {
        String componentId = component.getMarkupId();
        attributesJson.put(AjaxAttributeName.MARKUP_ID.jsonName(), componentId);
      }

      String formId = attributes.getFormId();
      if (Strings.isEmpty(formId) == false)
      {
        attributesJson.put(AjaxAttributeName.FORM_ID.jsonName(), formId);
      }

      if (attributes.isMultipart())
      {
        attributesJson.put(AjaxAttributeName.IS_MULTIPART.jsonName(), true);
      }

      String submittingComponentId = attributes.getSubmittingComponentName();
      if (Strings.isEmpty(submittingComponentId) == false)
      {
        attributesJson.put(AjaxAttributeName.SUBMITTING_COMPONENT_NAME.jsonName(),
          submittingComponentId);
      }

      String indicatorId = findIndicatorId();
      if (Strings.isEmpty(indicatorId) == false)
      {
        attributesJson.put(AjaxAttributeName.INDICATOR_ID.jsonName(), indicatorId);
      }

      for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners())
      {
        if (ajaxCallListener != null)
        {
          CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
          appendListenerHandler(beforeHandler, attributesJson,
            AjaxAttributeName.BEFORE_HANDLER.jsonName(),
            BEFORE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component);
          appendListenerHandler(beforeSendHandler, attributesJson,
            AjaxAttributeName.BEFORE_SEND_HANDLER.jsonName(),
            BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          appendListenerHandler(afterHandler, attributesJson,
            AjaxAttributeName.AFTER_HANDLER.jsonName(), AFTER_HANDLER_FUNCTION_TEMPLATE);

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          appendListenerHandler(successHandler, attributesJson,
            AjaxAttributeName.SUCCESS_HANDLER.jsonName(),
            SUCCESS_HANDLER_FUNCTION_TEMPLATE);

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          appendListenerHandler(failureHandler, attributesJson,
            AjaxAttributeName.FAILURE_HANDLER.jsonName(),
            FAILURE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          appendListenerHandler(completeHandler, attributesJson,
            AjaxAttributeName.COMPLETE_HANDLER.jsonName(),
            COMPLETE_HANDLER_FUNCTION_TEMPLATE);

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          appendListenerHandler(precondition, attributesJson,
            AjaxAttributeName.PRECONDITION.jsonName(), PRECONDITION_FUNCTION_TEMPLATE);
        }
      }

      JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters());

      if (extraParameters.length() > 0)
      {
        attributesJson.put(AjaxAttributeName.EXTRA_PARAMETERS.jsonName(), extraParameters);
      }

      List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
      if (dynamicExtraParameters != null)
      {
        for (CharSequence dynamicExtraParameter : dynamicExtraParameters)
        {
          String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE,
            dynamicExtraParameter);
          JsonFunction function = new JsonFunction(func);
          attributesJson.append(AjaxAttributeName.DYNAMIC_PARAMETER_FUNCTION.jsonName(),
            function);
        }
      }

      if (attributes.isAsynchronous() == false)
      {
        attributesJson.put(AjaxAttributeName.IS_ASYNC.jsonName(), false);
      }

      String[] eventNames = attributes.getEventNames();
      if (eventNames.length == 1)
      {
        attributesJson.put(AjaxAttributeName.EVENT_NAME.jsonName(), eventNames[0]);
      }
      else
      {
        for (String eventName : eventNames)
        {
          attributesJson.append(AjaxAttributeName.EVENT_NAME.jsonName(), eventName);
        }
      }

      AjaxChannel channel = attributes.getChannel();
      if (channel != null)
      {
        attributesJson.put(AjaxAttributeName.CHANNEL.jsonName(), channel);
      }

      if (attributes.isAllowDefault())
      {
        attributesJson.put(AjaxAttributeName.IS_ALLOW_DEFAULT.jsonName(), true);
      }

      Duration requestTimeout = attributes.getRequestTimeout();
      if (requestTimeout != null)
      {
        attributesJson.put(AjaxAttributeName.REQUEST_TIMEOUT.jsonName(),
          requestTimeout.getMilliseconds());
      }

      boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
      if (wicketAjaxResponse == false)
      {
        attributesJson.put(AjaxAttributeName.IS_WICKET_AJAX_RESPONSE.jsonName(), false);
      }

      String dataType = attributes.getDataType();
      if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false)
      {
        attributesJson.put(AjaxAttributeName.DATATYPE.jsonName(), dataType);
      }

      ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
      if (throttlingSettings != null)
      {
        JSONObject throttlingSettingsJson = new JSONObject();
        throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_ID.jsonName(),
          throttlingSettings.getId());
        throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_DELAY.jsonName(),
          throttlingSettings.getDelay().getMilliseconds());
        if (throttlingSettings.getPostponeTimerOnUpdate())
        {
          throttlingSettingsJson.put(
            AjaxAttributeName.THROTTLING_POSTPONE_ON_UPDATE.jsonName(), true);
        }
        attributesJson.put(AjaxAttributeName.THROTTLING.jsonName(), throttlingSettingsJson);
      }

View Full Code Here

    try
    {
      CoreLibrariesContributor.contributeAjax(component.getApplication(), response);

      response.render(JavaScriptHeaderItem.forReference(JQueryWicketAtmosphereResourceReference.get()));
      JSONObject options = findEventBus().getParameters().toJSON();
      options.put("url", getCallbackUrl());
      response.render(OnDomReadyHeaderItem.forScript("$('#" + component.getMarkupId() +
          "').wicketAtmosphere(" + options.toString() + ")"));
    }
    catch (JSONException e)
    {
      throw new WicketRuntimeException(e);
    }
View Full Code Here

TOP

Related Classes of org.apache.wicket.ajax.json.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.