Package org.apache.wicket.ajax.json

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


    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("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

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

      response.render(JavaScriptHeaderItem.forReference(JQueryWicketAtmosphereResourceReference.get()));
      JSONObject options = findEventBus().getParameters().toJSON();
      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

  /**
   * Read the Request and construct an appropriate ResourceStream to respond with.
   */
  public void buildResourceStream()
  {
    JSONObject json;
    String cmd = null, id = null;
    JSONArray paramArray = null;

    HttpServletRequest req = ((ServletWebRequest)RequestCycle.get().getRequest()).getContainerRequest();
    BufferedReader reader = null;
    try
    {
      ServletInputStream sis = req.getInputStream();
      reader = new BufferedReader(new InputStreamReader(sis, "UTF-8"));
      // Used for debugging:
      // reader.mark(10);
      // if (reader.read() == -1) {
      // LOG.error("No request seen");
      // }
      // reader.reset();

      json = new JSONObject(new JSONTokener(reader));
      // LOG.debug("JSON Object: {}", json);

      id = json.getString("id");
      cmd = json.getString("method");
      paramArray = json.getJSONArray("params");

    }
    catch (IOException e)
    {
      jsonError("I/O exception while parsing");
View Full Code Here

    {
      while (words.hasNext())
        array.put(words.next());
    }

    JSONObject response = new JSONObject();
    try
    {
      response.put("id", id);
      response.put("error", (String)null);
      response.put("result", array);
      setResponse(response.toString());
    }
    catch (JSONException e)
    {
      jsonError("Failed to construct response");
    }
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("obj1", obj1);
    jsonObject.put("obj2", obj2);
    jsonObject.put("num", num);

    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("p1", p1);
    jsonObject.put("p2", p2);

    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("obj1", obj1);
    jsonObject.put("obj2", obj2);
    jsonObject.put("num", num);

    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("p1", p1);
    jsonObject.put("p2", p2);
    return jsonObject;
  }
View Full Code Here

    if (!"".equals(loadedContent)) {
      whiteboardMap.get(whiteboardObjectId).setLoadedContent(loadedContent);
      if (whiteboardContent != null && !whiteboardContent.equals("")) {
        try {
          JSONObject savedContent = new JSONObject(whiteboardContent);

          JSONArray elementList = (JSONArray) savedContent.get("elements");
          snapShot = new ArrayList<Element>();
          snapShotCreation = new ArrayList<Boolean>();

          for (int i = 0; i < elementList.length(); i++) {
            JSONObject jElement = (JSONObject) elementList.get(i);

            Element element = getElementObject(jElement);

            if (element != null) {
              elementMap.put(element.getId(), element);
              loadedElementMap.put(element.getId(), element);
              snapShot.add(element);
              snapShotCreation.add(true);
            }
          }
          if (undoSnapshots.isEmpty()) {
            undoSnapshots.addLast(snapShot);
            undoSnapshotCreationList.addLast(snapShotCreation);
            isElementSnapshotList.addLast(true);
          }

          snapShot = null;
          snapShotCreation = null;

          if (savedContent.has("background")) {
            JSONObject backgroundJSON = (JSONObject) savedContent.get("background");
            background = new Background(backgroundJSON);
            whiteboardMap.get(whiteboardObjectId).setBackground(background);
            undoSnapshots_Background.addLast(new Background("Background", "", 0.0, 0.0, 0.0, 0.0));
            undoSnapshotCreationList_Background.addLast(true);
            isElementSnapshotList.addLast(false);
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.