@Override public Object createArray() { return new JSONArray(); }
@Override public Object createArray() { return new JSONArray(); }
@Override public Object createArray() { return new JSONArray(); }
@Override public JSONArray coerce(String input) { return new JSONArray(input); } }
@Override public JSONArray coerce(String input) { return new JSONArray(input); } }
public void with(Object... arguments) { assert arguments != null; this.arguments = new JSONArray(arguments); } }
/** * Create a new array, and adds all values fro the iterable to the array (using {@link #putAll(Iterable)}. * * This is implemented as a static method so as not to break the semantics of the existing {@link #JSONArray(Object...)} constructor. * Adding a constructor of type Iterable would change the meaning of <code>new JSONArray(new JSONArray())</code>. * * @param iterable * collection ot value to include, or null * @since 5.4 */ public static JSONArray from(Iterable<?> iterable) { return new JSONArray().putAll(iterable); }
/** * Create a new array, and adds all values fro the iterable to the array (using {@link #putAll(Iterable)}. * * This is implemented as a static method so as not to break the semantics of the existing {@link #JSONArray(Object...)} constructor. * Adding a constructor of type Iterable would change the meaning of <code>new JSONArray(new JSONArray())</code>. * * @param iterable * collection ot value to include, or null * @since 5.4 */ public static JSONArray from(Iterable<?> iterable) { return new JSONArray().putAll(iterable); }
public DefaultDataTableModel( TypeCoercer typeCoercer, TranslatorSource translatorSource, PageRenderQueue pageRenderQueue, AjaxFormUpdateController ajaxFormUpdateController, AjaxPartialResponseRenderer partialRenderer, FakeInheritedBinding row, FakeInheritedBinding rowIndex) { super(); this.typeCoercer = typeCoercer; this.translatorSource = translatorSource; this.pageRenderQueue = pageRenderQueue; this.ajaxFormUpdateController = ajaxFormUpdateController; this.partialRenderer = partialRenderer; this.rowParam = row; this.rowIndexParam = rowIndex; response = new JSONObject(); rows = new JSONArray() ; }
/** * Transforms the matches into a JSONArray * * @return JSONArray of available responses */ protected JSONArray generateResponseJSON(List matches) { JSONArray array = new JSONArray(); for (Object o : matches) { if (o instanceof JSONObject) array.put(o); else array.put(o.toString()); } return array; } }
private String convert(List<?> input) { return new JSONArray().putAll(input).toString(compactJSON); }
public void addScript(InitializationPriority priority, String script) { addInitialization(priority, "t5/core/pageinit", "evalJavaScript", new JSONArray().put(script)); }
public String getInitialJSON() { JSONArray array = new JSONArray(); for (Object o : selected) { String value = encoder.toClient(o); array.put(value); } return array.toString(compactJSON); }
private boolean selected(String clientId, String elementName) { // Case #1: via JavaScript, the client id is passed up. String raw = request.getParameter(Form.SUBMITTING_ELEMENT_ID); if (InternalUtils.isNonBlank(raw) && new JSONArray(raw).getString(0).equals(clientId)) { return true; } // Case #2: No JavaScript, look for normal semantic (non-null value for the element's name). // If configured as an image submit, look for a value for the x position. Ah, the ugliness // of HTML. String name = image == null ? elementName : elementName + ".x"; String value = request.getParameter(name); return value != null; }
private void addPublishEventInfo(Flow<EventHandlerMethod> eventHandlerMethods, MutableComponentModel model) { JSONArray publishEvents = new JSONArray(); for (EventHandlerMethod eventHandlerMethod : eventHandlerMethods) { if (eventHandlerMethod.publishEvent != null) { publishEvents.put(eventHandlerMethod.eventType.toLowerCase()); } } // If we do have events to publish, we apply the mixin and pass // event information to it. if (publishEvents.length() > 0) { model.addMixinClassName(PublishServerSideEvents.class.getName(), "after:*"); model.setMeta(InternalConstants.PUBLISH_COMPONENT_EVENTS_META, publishEvents.toString()); } }
@Override public org.apache.tapestry5.json.JSONObject tapestry(final Users obj) throws IOException { org.apache.tapestry5.json.JSONObject jso = new org.apache.tapestry5.json.JSONObject(); if (obj.users != null) { org.apache.tapestry5.json.JSONArray jsarr = new org.apache.tapestry5.json.JSONArray(); for (User u : obj.users) { jsarr.put(tapestry(u)); } jso.put("users", jsarr); } return jso; }
private void processSubmission(String clientId) { this.clientId = clientId; String raw = request.getParameter(Form.SUBMITTING_ELEMENT_ID); if (InternalUtils.isNonBlank(raw) && new JSONArray(raw).getString(0).equals(clientId)) { Runnable notification = new Runnable() { public void run() { resources.triggerEvent(event, context, eventCallback); } }; if (defer) formSupport.defer(notification); else heartbeat.defer(notification); } }
private boolean isFormCancelled() { // The "cancel" query parameter is reserved for this purpose; if it is present then the form was canceled on the // client side. For image submits, there will be two parameters: "cancel.x" and "cancel.y". if (request.getParameter(InternalConstants.CANCEL_NAME) != null || request.getParameter(InternalConstants.CANCEL_NAME + ".x") != null) { return true; } // When JavaScript is involved, it's more complicated. In fact, this is part of HLS's desire // to have all forms submit via XHR when JavaScript is present, since it would provide // an opportunity to get the submitting element's value into the request properly. String raw = request.getParameter(SUBMITTING_ELEMENT_ID); if (InternalUtils.isNonBlank(raw) && new JSONArray(raw).getString(1).equals(InternalConstants.CANCEL_NAME)) { return true; } return false; }
@Test public void response_sent() throws IOException { String encoding = "UTF-8"; Response response = mockResponse(); CharArrayWriter writer = new CharArrayWriter(); PrintWriter pw = new PrintWriter(writer); expect(response.getPrintWriter("application/json;charset=UTF-8")).andReturn(pw); replay(); JSONArray array = new JSONArray(" [ \"fred\", \"barney\" \n\n]"); JSONArrayEventResultProcessor p = new JSONArrayEventResultProcessor(response, encoding, false); p.processResultValue(array); verify(); assertEquals(writer.toString(), "[\n \"fred\",\n \"barney\"\n]"); } }
void beginRender(MarkupWriter writer) { JSONArray selectedValues = new JSONArray(); for (OptionModel selected : selectedOptions) { Object value = selected.getValue(); String clientValue = encoder.toClient(value); selectedValues.put(clientValue); } JSONArray naturalOrder = new JSONArray(); for (String value : this.naturalOrder) { naturalOrder.put(value); } String clientId = getClientId(); JSONObject options = new JSONObject(); options.put("id", clientId); options.put("reorder", reorder); options.put("naturalOrder", naturalOrder); javascriptSupport.require("tjq/palette").with(options); writer.element("input", "type", "hidden", "id", clientId + "-values", "name", getControlName() + "-values", "value", selectedValues); writer.end(); }