@Override public int length(final Object obj) { if (obj instanceof JSONArray) { return ((JSONArray) obj).length(); } else if (obj instanceof JSONObject) { return ((JSONObject) obj).length(); } else { throw new IllegalArgumentException("Cannot determine length of " + obj + ", unsupported type."); } }
@Override public int length(final Object obj) { if (obj instanceof JSONArray) { return ((JSONArray) obj).length(); } else if (obj instanceof JSONObject) { return ((JSONObject) obj).length(); } else { throw new IllegalArgumentException("Cannot determine length of " + obj + ", unsupported type."); } }
@Override public int length(final Object obj) { if (obj instanceof JSONArray) { return ((JSONArray) obj).length(); } else if (obj instanceof JSONObject) { return ((JSONObject) obj).length(); } else { throw new IllegalArgumentException("Cannot determine length of " + obj + ", unsupported type."); } }
Object onAutocomplete() { JSONObject json = new JSONObject(request.getParameter("data")); JSONObject extra = (json.length()>1) ? new JSONObject(json.getString(EXTRA_NAME)) : new JSONObject(); String input = json.getString(PARAM_NAME); final Holder<List> matchesHolder = Holder.create(); // Default it to an empty list. matchesHolder.put(Collections.emptyList()); ComponentEventCallback<List> callback = new ComponentEventCallback<List>() { public boolean handleResult(List result) { matchesHolder.put(result); return true; } }; Object[] params = extra.length()==0 ? new Object[] {input} : new Object[] {input, extra}; resources.triggerEvent(EventConstants.PROVIDE_COMPLETIONS, params, callback); ContentType contentType = responseRenderer.findContentType(this); return new TextStreamResponse(contentType.toString(), generateResponseJSON(matchesHolder.get()).toString()); }