Package org.richfaces.json

Examples of org.richfaces.json.JSONArray


    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            if (value.charAt(0) == '{') {
                return new JSONObject(value);
            }
            return new JSONArray(value);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
View Full Code Here


        String imageId = "";
        String albumId = "";
        JSONObject jo;

        try {
            JSONArray ja = new JSONArray(imagesArray);
            albumId = ja.getJSONObject(0).getString("fullAlbumId");

            currentAlbumId = albumId;

            if (images.get(albumId) != null) {
                // these images are already cached
                return;
            }
           
            int size = ja.length();
           
            // put size in the album
            albums.get(albumId).put("size", size);

            images.put(albumId, new HashMap<String, JSONObject>());

            for (int i = 0; i < size; i++) {
                jo = ja.getJSONObject(i);

                if (!jo.has("albumId") || !jo.has("id")) {
                    error.fire(new ErrorEvent("Error, object does not contain images"));

                }
View Full Code Here

    public void setAlbumAndImages(String aiJson) {
        try {
            JSONObject jAlbum = new JSONObject(aiJson);

            JSONArray albumImages = jAlbum.getJSONArray("images");
            jAlbum.remove("images");

            String albumId = jAlbum.getString("fullId");
            int size = albumImages.length();
           
            jAlbum.put("size", size);
            albums.put(albumId, jAlbum);
            images.put(albumId, new HashMap<String, JSONObject>());

            JSONObject jo;
            String imageId;
            Map<String, JSONObject> album = images.get(albumId);
            for (int i = 0; i < albumImages.length(); i++) {
                jo = albumImages.getJSONObject(i);

                if (!jo.has("id")) {
                    error.fire(new ErrorEvent("Error, object does not contain images"));
                }
View Full Code Here

        public VisitChart(AbstractChart ch) {
            this.nodata = true;
            this.chart = ch;
            this.chartType = null;
            this.data = new JSONArray();
            this.particularSeriesHandlers = new JSONObject();
            this.plotClickHandlers = new JSONArray();
            this.plothoverHandlers = new JSONArray();
            this.particularSeriesListeners = new LinkedList<MethodExpression>();


            try {
                addAttribute(particularSeriesHandlers, "onplotclick",
View Full Code Here

*/
public class PieStrategy implements ChartStrategy {

    @Override
    public Object export(ChartDataModel model) throws IOException {
        JSONArray jsData = new JSONArray();
        for (Iterator it = model.getData().entrySet().iterator(); it.hasNext();) {
            JSONObject point = new JSONObject();
            Map.Entry entry = (Map.Entry) it.next();
            try {
                point.put("label", entry.getKey());
                point.put("data", entry.getValue());
            } catch (JSONException ex) {
                throw new IOException(ex);
            }
            jsData.put(point);
        }
        return jsData;
    }
View Full Code Here

        return obj;
    }

    private double calculateBarWidth(JSONObject o) {
        JSONArray data = o.optJSONArray("data");

        if (data != null) {
            JSONArray last = data.optJSONArray(data.length() - 1);
            if (last != null) {
                // x value of last element ~ number of ticks
                // barWidth = 1 / (points-per-tick + 1)
                return 1 / (data.length() / last.optDouble(0) + 1);
            }
        }

        return 1.0;
    }
View Full Code Here

    public List<JSONObject> getUserAlbums() {
        return userAlbums;
    }

    public void setUserAlbumsJSON(String albumJson) {
        JSONArray ja = new JSONArray();
        this.userAlbums = new ArrayList<JSONObject>();

        try {
            ja = new JSONArray(albumJson);

            for (int i = 0; i < ja.length(); i++) {
                userAlbums.add(ja.getJSONObject(i));
            }

            gpac.storeAlbums(userAlbums);
        } catch (JSONException e) {
            error.fire(new ErrorEvent("Error", e.getMessage()));
View Full Code Here

        keys.remove(key);
    }

    public JSONObject defaultExport() throws IOException {
        JSONObject output = new JSONObject();
        JSONArray jsdata;

        // data
        jsdata = new JSONArray();

        for (T key : keys) {
            JSONArray point = new JSONArray();
            S value = (S) data.get(key);
            point.put(key);
            point.put(value);
            jsdata.put(point);
        }

        ChartRendererBase.addAttribute(output, "data", jsdata);
        // label
View Full Code Here

class DateLineStrategy implements ChartStrategy {

    @Override
    public Object export(ChartDataModel model) throws IOException {
        JSONObject output = new JSONObject();
        JSONArray jsdata;

        // data
        jsdata = new JSONArray();
        for (Iterator it = model.getData().entrySet().iterator(); it.hasNext();) {
            JSONArray point = new JSONArray();
            Map.Entry entry = (Map.Entry) it.next();
            point.put(((Date) entry.getKey()).getTime());
            point.put(entry.getValue());
            jsdata.put(point);
        }
        ChartRendererBase.addAttribute(output, "data", jsdata);
        // label
        ChartRendererBase.addAttribute(output, "label", model.getAttributes()
View Full Code Here

  private void populateProjectNameItems() {
    if(super.getContext().getHttpsClient()!=null){
      HTTPSClient httpsClient = super.getContext().getHttpsClient();
      try {
        String content = httpsClient.getTextFromURL("https://info.teragrid.org:8444/web-apps/json/profile-v1/project",super.getContext().getCredentials().getMyproxyUserName(),super.getContext().getCredentials().getMyproxyPassword());
        JSONArray jsonArray = new JSONArray(content);
        for(int i=0;i<jsonArray.length();i++){
          JSONObject jsonObject = jsonArray.getJSONObject(i);
          projectNameItems.add(new SelectItem(jsonObject.get("projectId")));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
View Full Code Here

TOP

Related Classes of org.richfaces.json.JSONArray

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.