elemental.json.JsonObject.put()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中elemental.json.JsonObject.put()方法的一些代码示例,展示了JsonObject.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject.put()方法的具体详情如下:
包路径:elemental.json.JsonObject
类名称:JsonObject
方法名:put

JsonObject.put介绍

[英]Set a given key to the given double value.
[中]将给定的键设置为给定的双精度值。

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

private void putValueOrNull(JsonObject object, String key, String value) {
    assert object != null;
    assert key != null;
    if (value == null) {
      object.put(key, Json.createNull());
    } else {
      object.put(key, value);
    }
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

private static void putValueOrJsonNull(JsonObject json, String key,
    String value) {
  if (value == null) {
    json.put(key, Json.createNull());
  } else {
    json.put(key, value);
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

private static String stringify(TimeZoneInfo info) {
  JreJsonFactory factory = new JreJsonFactory();
  JsonObject object = factory.createObject();
  object.put("id", info.id);
  object.put("std_offset", info.stdOffset);
  object.put("names", getArray(factory, info.names));
  object.put("transitions", getArray(factory, info.transitions));
  return JsonUtil.stringify(object);
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Drag data generator. Appends drag data to row data json if generator
 * function(s) are set by the user of this extension.
 *
 * @param item
 *            Row item for data generation.
 * @param jsonObject
 *            Row data in json format.
 */
private void generateDragData(T item, JsonObject jsonObject) {
  JsonObject generatedValues = Json.createObject();
  generatorFunctions.forEach((type, generator) -> generatedValues
      .put(type, generator.apply(item)));
  jsonObject.put(GridDragSourceState.JSONKEY_DRAG_DATA, generatedValues);
}

代码示例来源:origin: com.vaadin/vaadin-server

public String asJson() {
  JsonArray uris = Json.createArray();
  for (String uri : sourceUris) {
    uris.set(uris.length(), uri);
  }
  JsonObject object = Json.createObject();
  object.put("version", Version.getFullVersion());
  object.put("timestamp", Long.toString(timestamp));
  object.put("uris", uris);
  object.put("css", css);
  return object.toJson();
}

代码示例来源:origin: com.vaadin/vaadin-server

private static JsonObject encodeStringMap(Type valueType, Map<?, ?> map,
    ConnectorTracker connectorTracker) {
  JsonObject jsonMap = Json.createObject();
  for (Entry<?, ?> entry : map.entrySet()) {
    String key = (String) entry.getKey();
    EncodeResult encodedValue = encode(entry.getValue(), null,
        valueType, connectorTracker);
    jsonMap.put(key, encodedValue.getEncodedValue());
  }
  return jsonMap;
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void generateData(T item, JsonObject jsonObject) {
  if (isSelected(item)) {
    // Pre-emptive update in case used a stale element in selection.
    refreshData(item);
    jsonObject.put(DataCommunicatorConstants.SELECTED, true);
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void generateData(T item, JsonObject jsonObject) {
  JsonObject hierarchyData = Json.createObject();
  int depth = getDepth(item);
  if (depth >= 0) {
    hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_DEPTH,
        depth);
  }
  boolean isLeaf = !getDataProvider().hasChildren(item);
  if (isLeaf) {
    hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_LEAF,
        true);
  } else {
    hierarchyData.put(
        HierarchicalDataCommunicatorConstants.ROW_COLLAPSED,
        !isExpanded(item));
    hierarchyData.put(HierarchicalDataCommunicatorConstants.ROW_LEAF,
        false);
    hierarchyData.put(
        HierarchicalDataCommunicatorConstants.ROW_COLLAPSE_ALLOWED,
        getItemCollapseAllowedProvider().test(item));
  }
  // add hierarchy information to row as metadata
  jsonObject.put(
      HierarchicalDataCommunicatorConstants.ROW_HIERARCHY_DESCRIPTION,
      hierarchyData);
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void generateData(T item, JsonObject jsonObject) {
  ColumnState state = getState(false);
  String communicationId = getConnectorId();
  assert communicationId != null : "No communication ID set for column "
      + state.caption;
  JsonObject obj = getDataObject(jsonObject,
      DataCommunicatorConstants.DATA);
  obj.put(communicationId, generateRendererValue(item,
      presentationProvider, state.renderer));
  String style = styleGenerator.apply(item);
  if (style != null && !style.isEmpty()) {
    JsonObject styleObj = getDataObject(jsonObject,
        GridState.JSONKEY_CELLSTYLES);
    styleObj.put(communicationId, style);
  }
  if (descriptionGenerator != null) {
    String description = descriptionGenerator.apply(item);
    if (description != null && !description.isEmpty()) {
      JsonObject descriptionObj = getDataObject(jsonObject,
          GridState.JSONKEY_CELLDESCRIPTION);
      descriptionObj.put(communicationId, description);
    }
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void generateData(T item, JsonObject jsonObject) {
  if (generator == null || !visibleDetails.contains(item)) {
    return;
  }
  if (!components.containsKey(item)) {
    Component detailsComponent = generator.apply(item);
    Objects.requireNonNull(detailsComponent,
        "Details generator can't create null components");
    if (detailsComponent.getParent() != null) {
      throw new IllegalStateException(
          "Details component was already attached");
    }
    addComponentToGrid(detailsComponent);
    components.put(item, detailsComponent);
  }
  jsonObject.put(GridState.JSONKEY_DETAILS_VISIBLE,
      components.get(item).getConnectorId());
}

代码示例来源:origin: com.vaadin/vaadin-server

private JsonArray toJsonArray(List<Dependency> list) {
  JsonArray result = Json.createArray();
  for (int i = 0; i < list.size(); i++) {
    JsonObject dep = Json.createObject();
    Dependency dependency = list.get(i);
    dep.put("type", dependency.getType().name());
    dep.put("url", dependency.getUrl());
    result.set(i, dep);
  }
  return result;
}

代码示例来源:origin: com.vaadin/vaadin-server

private static JsonObject encodeConnectorMap(Type valueType, Map<?, ?> map,
    ConnectorTracker connectorTracker) {
  JsonObject jsonMap = Json.createObject();
  for (Entry<?, ?> entry : map.entrySet()) {
    ClientConnector key = (ClientConnector) entry.getKey();
    if (LegacyCommunicationManager.isConnectorVisibleToClient(key)) {
      EncodeResult encodedValue = encode(entry.getValue(), null,
          valueType, connectorTracker);
      jsonMap.put(key.getConnectorId(),
          encodedValue.getEncodedValue());
    }
  }
  return jsonMap;
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void generateData(T item, JsonObject jsonObject) {
  String caption = getItemCaptionGenerator().apply(item);
  if (caption == null) {
    caption = "";
  }
  jsonObject.put(DataCommunicatorConstants.NAME, caption);
  String style = itemStyleGenerator.apply(item);
  if (style != null) {
    jsonObject.put(ComboBoxConstants.STYLE, style);
  }
  Resource icon = getItemIcon(item);
  if (icon != null) {
    String iconKey = resourceKeyMap
        .get(getDataProvider().getId(item));
    String iconUrl = ResourceReference
        .create(icon, ComboBox.this, iconKey).getURL();
    jsonObject.put(ComboBoxConstants.ICON, iconUrl);
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Gets a data object with the given key from the given JsonObject. If
 * there is no object with the key, this method creates a new
 * JsonObject.
 *
 * @param jsonObject
 *            the json object
 * @param key
 *            the key where the desired data object is stored
 * @return data object for the given key
 */
private JsonObject getDataObject(JsonObject jsonObject, String key) {
  if (!jsonObject.hasKey(key)) {
    jsonObject.put(key, Json.createObject());
  }
  return jsonObject.getObject(key);
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
   * Sets the expected value of a state property so that changes can be
   * properly sent to the client. This needs to be done in cases where a state
   * change originates from the client, since otherwise the server-side would
   * fail to recognize if the value is changed back to its previous value.
   *
   * @param propertyName
   *            the name of the shared state property to update
   * @param newValue
   *            the new diffstate reference value
   */
  protected void updateDiffstate(String propertyName, JsonValue newValue) {
    if (!isAttached()) {
      return;
    }

    JsonObject diffState = getUI().getConnectorTracker().getDiffState(this);
    if (diffState == null) {
      return;
    }

    assert diffState.hasKey(propertyName) : "Diffstate for "
        + getClass().getName() + " has no property named "
        + propertyName;

    diffState.put(propertyName, newValue);
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
protected JsonObject getApplicationParameters(BootstrapContext context) {
  JsonObject parameters = super.getApplicationParameters(context);
  VaadinPortletResponse response = (VaadinPortletResponse) context
      .getResponse();
  VaadinPortletRequest request = (VaadinPortletRequest) context
      .getRequest();
  MimeResponse portletResponse = (MimeResponse) response
      .getPortletResponse();
  ResourceURL resourceURL = portletResponse.createResourceURL();
  resourceURL.setResourceID("v-browserDetails");
  parameters.put("browserDetailsUrl", resourceURL.toString());
  String serviceUrlParameterName = ApplicationConstants.V_RESOURCE_PATH;
  // If we are running in Liferay then we need to prefix all parameters
  // with the portlet namespace
  if (request instanceof VaadinLiferayRequest) {
    serviceUrlParameterName = response.getPortletResponse()
        .getNamespace() + serviceUrlParameterName;
  }
  parameters.put(ApplicationConstants.SERVICE_URL_PARAMETER_NAME,
      serviceUrlParameterName);
  return parameters;
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Constructs a new CheckBoxGroup.
 */
public CheckBoxGroup() {
  registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
  addDataGenerator((item, jsonObject) -> {
    String description = getItemDescriptionGenerator().apply(item);
    if (description != null) {
      jsonObject.put(ListingJsonConstants.JSONKEY_ITEM_DESCRIPTION,
          description);
    }
  });
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Triggered when the user unchecks the select all checkbox.
 *
 * @param userOriginated
 *            {@code true} if originated from client side by user
 */
protected void onDeselectAll(boolean userOriginated) {
  if (userOriginated) {
    verifyUserCanSelectAll();
    // all selected state has been update in client side already
    getState(false).allSelected = false;
    getUI().getConnectorTracker().getDiffState(this).put("allSelected",
        false);
  } else {
    getState().allSelected = false;
  }
  updateSelection(Collections.emptySet(), new LinkedHashSet<>(selection),
      userOriginated);
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public boolean synchronizedHandleRequest(VaadinSession session,
    VaadinRequest request, VaadinResponse response) throws IOException {
  try {
    assert UI.getCurrent() == null;
    // Update browser information from the request
    session.getBrowser().updateRequestDetails(request);
    UI uI = getBrowserDetailsUI(request, session);
    session.getCommunicationManager().repaintAll(uI);
    JsonObject params = Json.createObject();
    params.put(UIConstants.UI_ID_PARAMETER, uI.getUIId());
    String initialUIDL = getInitialUidl(request, uI);
    params.put("uidl", initialUIDL);
    return commitJsonResponse(request, response,
        JsonUtil.stringify(params));
  } catch (JsonException e) {
    throw new IOException("Error producing initial UIDL", e);
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Creates a new {@code NativeSelect} with an empty caption and no items.
 */
public NativeSelect() {
  registerRpc(new FocusAndBlurServerRpcDecorator(this, this::fireEvent));
  addDataGenerator((item, json) -> {
    String caption = getItemCaptionGenerator().apply(item);
    if (caption == null) {
      caption = "";
    }
    json.put(DataCommunicatorConstants.DATA, caption);
  });
  setItemCaptionGenerator(String::valueOf);
}

相关文章