Package org.apache.wicket.ajax.json

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


   *
   * @return JSON object with field values added
   * @throws JSONException
   */
  public JSONObject getJSON() throws JSONException {
    JSONObject jsonObject = super.getJSON(new JSONObject());
    jsonObject.put("p", p);
    jsonObject.put("age", age);

    return jsonObject;
  }
View Full Code Here


   *
   * @return JSON object with field values added
   * @throws JSONException
   */
  public JSONObject getJSON() throws JSONException {
    JSONObject jsonObject = super.getJSON(new JSONObject());
    jsonObject.put("obj", obj);
    jsonObject.put("s", s);
    jsonObject.put("t", t);

    return jsonObject;
  }
View Full Code Here

   *
   * @return JSON object with field values added
   * @throws JSONException
   */
  public JSONObject getJSON() throws JSONException {
    JSONObject jsonObject = super.getJSON(new JSONObject());
    jsonObject.put("r", r);

    return jsonObject;

  }
View Full Code Here

    public Geocoder()
    {
    }

    public GLatLng decode(String response) throws GeocoderException, JSONException {
        JSONObject jsonResponse = new JSONObject(response);
        GeocoderStatus status = GeocoderStatus.valueOf(jsonResponse.getString("status"));
        if (status != GeocoderStatus.OK) {
            throw new GeocoderException(status);
        }
        JSONArray results = jsonResponse.getJSONArray("results");
        JSONObject location = results.getJSONObject(0).getJSONObject("geometry").getJSONObject("location");
        return new GLatLng(location.getDouble("lat"), location.getDouble("lng"));
    }
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)
          {
            String func = String.format(BEFORE_HANDLER_FUNCTION_TEMPLATE, beforeHandler);
            JsonFunction function = new JsonFunction(func);
            attributesJson.append("bh", function);
          }

          CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
          if (Strings.isEmpty(afterHandler) == false)
          {
            String func = String.format(AFTER_HANDLER_FUNCTION_TEMPLATE, afterHandler);
            JsonFunction function = new JsonFunction(func);
            attributesJson.append("ah", function);
          }

          CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
          if (Strings.isEmpty(successHandler) == false)
          {
            String func = String.format(SUCCESS_HANDLER_FUNCTION_TEMPLATE, successHandler);
            JsonFunction function = new JsonFunction(func);
            attributesJson.append("sh", function);
          }

          CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
          if (Strings.isEmpty(failureHandler) == false)
          {
            String func = String.format(FAILURE_HANDLER_FUNCTION_TEMPLATE, failureHandler);
            JsonFunction function = new JsonFunction(func);
            attributesJson.append("fh", function);
          }

          CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
          if (Strings.isEmpty(completeHandler) == false)
          {
            String func = String.format(COMPLETE_HANDLER_FUNCTION_TEMPLATE, completeHandler);
            JsonFunction function = new JsonFunction(func);
            attributesJson.append("coh", function);
          }

          CharSequence precondition = ajaxCallListener.getPrecondition(component);
          if (Strings.isEmpty(precondition) == false)
          {
            String func = String.format(PRECONDITION_FUNCTION_TEMPLATE, precondition);
            JsonFunction function = new JsonFunction(func);
            attributesJson.append("pre", function);
          }
        }
      }

      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

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.