Package org.richfaces.json

Examples of org.richfaces.json.JSONObject


        while((line = reader.readLine()) != null) {
         builder.append(line);
        }

        try {
            JSONObject json = new JSONObject(builder.toString());
            // now have some fun with the results...
            System.out.println("GOT: "+json.toString(2));
        } catch (JSONException e) {
            // FIXME Auto-generated catch block
            e.printStackTrace();
        }
       
View Full Code Here


        ExtDraggableRendererContributor contributor = ExtDraggableRendererContributor
                .getInstance();
        ScriptOptions dragOptions = contributor.buildOptions(context, column,
                dragSourceScriptId, indicatorId);

        JSONObject dndParams = new JSONObject();
        try {
            dndParams.put("label", dragLabel == null ? "" : dragLabel);
        } catch (JSONException e) {
        }
        dragOptions.addOption("dndParams", dndParams.toString());

        function.addParameter(dragOptions);
        function.appendScript(buffer);

        String scriptContribution = contributor.getScriptContribution(context,
View Full Code Here

        String varName = "DnD_ExtSimpleDropZone_"+column.getId().replaceAll("[^A-Za-z0-9_]", "_") + (before?"L":"R");
        StringBuffer buffer = new StringBuffer("delete " + varName + ";\nvar " + varName + " = ");
        JSFunction function = new JSFunction("new DnD.ExtSimpleDropZone");
        function.addParameter(dropTargetId);
        ScriptOptions dropOptions = contributor.buildOptions(context, column);
        JSONObject dndParams = new JSONObject();
        dropOptions.addOption("dndParams", dndParams.toString());

        function.addParameter(dropOptions);
        function.appendScript(buffer);

        String dropTargetScriptId = column.getClientId(context) + ":"
View Full Code Here

    Set entrySet = params.entrySet();
    for (Iterator iterator = entrySet.iterator(); iterator.hasNext();) {
      Map.Entry entry = (Map.Entry) iterator.next();

      String name = (String) entry.getKey();
      JSONObject dndParams = (JSONObject) entry.getValue();

      if (dndParams != null) {
        responseWriter.writeAttribute(NSUtils.XMLNS_PREFIX + ":" + name + "dndparams",
            dndParams.toString(), null);
      }
    }
  }
View Full Code Here

  }

  public String doEncodeAsString(FacesContext context, UIComponent component)
  throws IOException {

    JSONObject merged = new JSONObject();

    try {

      Map map = doEncodeAsMap(context, component);
      for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();

        if (entry.getValue() != null) {
          JSONObject object = (JSONObject) entry.getValue();

          for (Iterator keys = object.keys(); keys.hasNext(); ) {
            String key = (String) keys.next();

            merged.put(key, object.get(key));
          }
        }
      }
    } catch (JSONException e) {
      IOException exception = new IOException(e.getMessage());
View Full Code Here

    return merged.toString();
  }

  protected Map doEncodeAsMap(FacesContext context, UIComponent component) throws IOException {
    Map params = new LinkedHashMap();
    params.put(DEFAULT, new JSONObject());

    boolean isDraggable = component instanceof Draggable;
    if (isDraggable) {
      params.put(DRAG, new JSONObject());
    }

    boolean isDropzone = component instanceof Dropzone;
    if (isDropzone) {
      params.put(DROP, new JSONObject());
    }

    try {
      if (component.getChildCount() != 0) {
        List children = component.getChildren();

        for (Iterator iterator = children.iterator(); iterator.hasNext();) {
          Object object = (Object) iterator.next();

          if (object instanceof UIDndParam) {
            UIDndParam dndParam = (UIDndParam) object;
            String type = dndParam.getType();
            JSONObject dndParams = null;

            if (DRAG.equals(type)) {
              if (isDraggable) {
                dndParams = (JSONObject) params.get(DRAG);
              } else {
                String messageString = MessageFormat.format(MESSAGE_CAST, new Object[] {
                    MessageUtil.getLabel(context, dndParam),
                    type,
                    MessageUtil.getLabel(context, component),
                    Draggable.class.getSimpleName()
                });

                FacesMessage message = new FacesMessage(messageString, messageString);
                context.addMessage(component.getClientId(context), message);
              }
            } else if (DROP.equals(type)) {
              if (isDropzone) {
                dndParams = (JSONObject) params.get(DROP);
              } else {
                String messageString = MessageFormat.format(MESSAGE_CAST, new Object[] {
                    MessageUtil.getLabel(context, dndParam),
                    type,
                    MessageUtil.getLabel(context, component),
                    Dropzone.class.getSimpleName()
                });

                FacesMessage message = new FacesMessage(messageString, messageString);
                context.addMessage(component.getClientId(context), message);
              }
            } else if (type == null || type.length() == 0 || DEFAULT.equals(type)) {
              dndParams = (JSONObject) params.get(DEFAULT);
            } else {
              String messageString = MessageFormat.format(MESSAGE_UNK_TYPE, new Object[] {
                  MessageUtil.getLabel(context, dndParam),
                  type
              });

              throw new IllegalArgumentException(messageString);
            }

            if (dndParams != null) {
              if (dndParam.isRendered()) {

                ResponseWriter responseWriter = context.getResponseWriter();
                StringWriter dumpWriter = new StringWriter();

                try {
                  context.setResponseWriter(responseWriter.cloneWithWriter(dumpWriter));

                  if (dndParam.getChildCount() == 0) {
                    context.getResponseWriter().writeText(dndParam.getValue(), null);
                  } else {
                    List paramChildren = dndParam.getChildren();

                    for (Iterator paramIterator = paramChildren
                        .iterator(); paramIterator.hasNext();) {

                      UIComponent paramChild = (UIComponent) paramIterator.next();
                      renderChild(context, paramChild);

                   
                  }

                  context.getResponseWriter().flush();
                } finally {
                  context.setResponseWriter(responseWriter);
                }

                String childContent = dumpWriter.getBuffer().toString();
                dndParams.put(dndParam.getName(), childContent);
              }
            }
          }
        }
      }

      Set entrySet = params.entrySet();
      for (Iterator iterator = entrySet.iterator(); iterator.hasNext();) {
        Map.Entry entry = (Map.Entry) iterator.next();

        JSONObject dndParams = (JSONObject) entry.getValue();

        if (dndParams.length() == 0) {
          entry.setValue(null);
        }
      }
    } catch (JSONException e) {
      IOException exception = new IOException(e.getMessage());
View Full Code Here

  /**
   * Get state in JSON format.
   * @return JSON object contains state
   */
  public JSONObject toJSON(){
    JSONObject result = new JSONObject();
    if (columnId != null){
      try {
        result.put("columnId", columnId);
        result.put("order", ordering);
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }
    return result;
View Full Code Here

  public String toString(){
    return toJSON().toString();
  }//toString
 
  public JSONObject toJSON(){
    JSONObject result = new JSONObject();
    try {
      result.put("columnsOrder", columnsOrder.toJSON());
      result.put("columnsVisibility", columnsVisibility.toJSON());
      result.put("columnsSizeState", columnsSizeState.toJSON());
      result.put("columnGroupingState", columnGroupingState.toJSON());
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return result;
  }
View Full Code Here

   * Converts its state from String representation or create default state if it is not set.
   */
  private void init(UIExtendedDataTable extendedDataTable, JSONMap state){
    value = null;
    if ((state != null) && (state.size()>0)){
      value = new JSONObject(state);
    }
   
    if (value == null){
      createDefaultColumnsSizeState(extendedDataTable);
    }
View Full Code Here

      JSONWriter writer = new JSONStringer().object();
      for (Iterator<UIColumn> iter = extendedDataTable.getChildColumns(); iter.hasNext();) {
        UIColumn col = iter.next();
        writer.key(col.getId()).value(getDefaultColumnSize(col));
      }
      value = new JSONObject(writer.endObject().toString());
    } catch (JSONException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

TOP

Related Classes of org.richfaces.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.