Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


     */
    public static JSONObject parseJSONParameter(IComponent component, String parameterName)
    {
        IBinding binding = component.getBinding(parameterName);
        if (binding == null || binding.getObject() == null)
            return new JSONObject();
       
        try
        {
            return new JSONObject((String) binding.getObject(String.class));
        }
        catch (ParseException ex)
        {
            throw new ApplicationRuntimeException( DojoMessages.mustUseValidJsonInParameter(parameterName),
                    binding.getLocation() , ex);
View Full Code Here


        renderInformalParameters(writer, cycle);
        renderBody(writer, cycle);
       
        writer.end();
       
        JSONObject obj = DojoUtils.parseJSONParameter(this, "options");

        obj.put("labelNode", getLabelNode());
        obj.put("labelNodeClass", getLabelNodeClass());
        obj.put("label", getLabel());
        obj.put("containerNodeClass", getContainerNodeClass());     

        //Setup our script includes
        Map scriptParms = new HashMap();
        scriptParms.put("id", getIdParameter());
        scriptParms.put("props", obj.toString());
        PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
        getScript().execute(cycle, pageRenderSupport, scriptParms);
    }
View Full Code Here

    public JSONWriterImpl(PrintWriter writer)
    {
        Defense.notNull(writer, "writer");
       
        _writer = writer;
        _json = new JSONObject();
    }
View Full Code Here

        renderInformalParameters(writer, cycle);
        renderBody(writer, cycle);
       
        writer.end();
       
        JSONObject obj = DojoUtils.parseJSONParameter(this, "options");

        obj.put("title", getTitle());
        if (getIcon() != null)
            obj.put("iconSrc", getIcon().buildURL());
        if (getHref() != null)
            obj.put("href", getHref());
        obj.put("widgetId", getId());
        obj.put("toggle", "fade");
        obj.put("constrainToContainer", getConstrainToContainer());
        obj.put("displayMaximizeAction", getDisplayMaximizeAction());
        obj.put("displayMinimizeAction", getDisplayMinimizeAction());
        obj.put("displayCloseAction", getDisplayCloseAction());
        obj.put("hasShadow", getHasShadow());
        obj.put("resizable", isResizable());
        obj.put("taskBarId", getTaskBarId());
        //obj.put("persistenceWidgetPosition", getPersistPosition());       

        //Setup our script includes
        Map scriptParms = new HashMap();
        scriptParms.put("id", getIdParameter());
        scriptParms.put("props", obj.toString());
        PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this);
        getScript().execute(cycle, pageRenderSupport, scriptParms);
    }
View Full Code Here

        ILink link = getDirectService().getLink(true, new DirectServiceParameter(this));
       
        Map parms = new HashMap();
        parms.put("id", getClientId());
       
        JSONObject json = new JSONObject();
        json.put("dataUrl", link.getURL() + "&filter=%{searchString}");
        json.put("mode", MODE_REMOTE);
        json.put("widgetId", getName());
        json.put("name", getName());
       
        IPropertySelectionModel model = getModel();
        if (model == null)
            throw Tapestry.createRequiredParameterException(this, "model");
       
        int count = model.getOptionCount();
        Object value = getValue();
       
        for (int i = 0; i < count; i++) {
            Object option = model.getOption(i);
           
            if (isEqual(option, value)) {
                json.put("value", model.getValue(i));
                json.put("label", model.getLabel(i));
                break;
            }
        }
       
        parms.put("props", json.toString());
        parms.put("form", getForm().getName());
       
        PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
        getScript().execute(cycle, prs, parms);
    }
View Full Code Here

       
        writer.end();
        renderDelegateSuffix(writer, cycle);
       
        // now create widget parms
        JSONObject json = new JSONObject();
        json.put("inputId", getClientId());
        json.put("inputName", getName());
        json.put("iconAlt", getIconAlt());
        json.put("dateFormat", Strftime.convertToPosixFormat(translator.getPattern()));
        if (getValue() != null)
            json.put("date", DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL,
                    getPage().getLocale()).format(getValue()));
       
        Map parms = new HashMap();
        parms.put("clientId", getClientId());
        parms.put("props", json.toString());
       
        getScript().execute(cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
    }
View Full Code Here

       
        writer.end();
        renderDelegateSuffix(writer, cycle);
       
        // now create widget parms
        JSONObject json = new JSONObject();
        json.put("inputId", getClientId());
        json.put("inputName", getName());
        json.put("iconAlt", getIconAlt());
        json.put("dateFormat", Strftime.convertToPosixFormat(translator.getPattern()));
        if (getValue() != null)
            json.put("date", getTranslatedFieldSupport().format(this, getValue()));
       
        Map parms = new HashMap();
        parms.put("clientId", getClientId());
        parms.put("props", json.toString());
       
        getScript().execute(cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
    }
View Full Code Here

       
        _rewinding = cycle.isRewound(form);
        _allocatedIdIndex = 0;
       
        _pageRenderSupport = TapestryUtils.getOptionalPageRenderSupport(cycle);
        _profile = new JSONObject();
    }
View Full Code Here

        boolean isAsync = isAsync() || update != null && update.size() > 0;

        if (!isAsync && type.equals(FormConstants.SUBMIT_NORMAL))
            return;
       
        JSONObject json = null;

        // build async URL to form if async

        if (isAsync)
        {
            IForm form = getForm();
           
            json = new JSONObject();
            json.put("async", Boolean.TRUE);
            json.put("json", isJson());
           
            DirectServiceParameter dsp = new DirectServiceParameter(form, null, this);
            json.put("url", getDirectService().getLink(true, dsp).getURL());
        }

        // only if not async - otherwise we have to stop the client side event to prevent normal form submission
        // within the submitbindings client side generated function
       
        if (!isAsync && !isParameterBound("onClick") && !isParameterBound("onclick"))
        {
            StringBuffer str = new StringBuffer();

            str.append("tapestry.form.").append(type);
            str.append("('").append(getForm().getClientId()).append("',");
            str.append("'").append(getName()).append("'");

            if (json != null)
                str.append(",").append(json.toString());

            str.append(")");
           
            writer.attribute("onClick", str.toString());
            return;
        }

        Map parms = new HashMap();
        parms.put("submit", this);
        parms.put("key", ScriptUtils.functionHash(type + this.hashCode()));
        parms.put("type", type);

        if (json != null)
            parms.put("parms", json.toString());
       
        PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
        getSubmitScript().execute(this, cycle, prs, parms);
    }
View Full Code Here

            String js = "tapestry.form." + type + "('" + form.getClientId() + "', '" + getName() + "'";
           
            if (isAsync)
            {
                JSONObject json = new JSONObject();
                json.put(new JSONLiteral("async"), Boolean.TRUE);
                json.put(new JSONLiteral("json"), isJson());

                DirectServiceParameter dsp = new DirectServiceParameter(form, null, this);
                json.put(new JSONLiteral("url"), new JSONLiteral("this.href"));

                writer.attribute("href", getDirectService().getLink(true, dsp).getURL());
                writer.attribute("onClick", js + "," + json.toString() + "); return false;");                       
            } else {

                writer.attribute("href", "javascript:" + js + ");");
            }
View Full Code Here

TOP

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