Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


        writer.attribute("class", getUpdateElementClass());
        writer.end();

        // render javascript

        JSONObject json = null;
        String options = getOptions();

        try {

            json = options != null ? new JSONObject(options) : new JSONObject();

        } catch (ParseException ex)
        {
            throw new ApplicationRuntimeException(ScriptaculousMessages.invalidOptions(options, ex), this.getBinding("options").getLocation(), ex);
        }

        // bind onFailure client side function if not already defined

        if (!json.has("onFailure"))
        {
            json.put("onFailure", "tapestry.error");
        }

        if (!json.has("encoding"))
        {
            json.put("encoding", cycle.getEngine().getOutputEncoding());
        }

        Map parms = new HashMap();
        parms.put("inputId", getClientId());
        parms.put("updateId", getClientId() + "choices");
        parms.put("options", json.toString());

        Object[] specifiedParams = DirectLink.constructServiceParameters(getParameters());
        Object[] listenerParams = null;
        if (specifiedParams != null)
        {
View Full Code Here


   
    public void test_Json_Time()
    {
        long time = System.currentTimeMillis();
       
        JSONObject json = new JSONObject();
        json.put("time", time);
       
        assertEquals(json.toString(), "{\"time\":"+time+"}");
    }
View Full Code Here

        renderDelegateSuffix(writer, cycle);
       
        Map parms = new HashMap();
        parms.put("id", getClientId());
       
        JSONObject json = new JSONObject();
        if (!isLocal())
        {
            ILink link = getDirectService().getLink(true, new DirectServiceParameter(this));
            json.put("dataUrl", link.getURL() + "&filter=%{searchString}");
        }
        json.put("mode", isLocal() ? MODE_LOCAL : MODE_REMOTE);
        json.put("widgetId", getName());
        json.put("name", getName());
        json.put("searchDelay", getSearchDelay());
        json.put("fadeTime", getFadeTime());
        json.put("maxListLength", getMaxListLength());
        json.put("forceValidOption", isForceValidOption());
        json.put("disabled", isDisabled());
       
        json.put("value", getDataSqueezer().squeeze(key));
        json.put("label", value != null ? model.getLabelFor(value) : "");
       
        parms.put("props", json.toString());
        parms.put("form", getForm().getName());
        parms.put("widget", this);
       
        PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
        getScript().execute(this, cycle, prs, parms);
View Full Code Here

        if (!cycle.isRewinding())
            writer.end();
       
        if (!cycle.isRewinding())
        {
            JSONObject json = new JSONObject();
            json.put("bgColor", getBackgroundColor());
            json.put("bgOpacity", getOpacity());

            Map parms = new HashMap();
            parms.put("component", this);
            parms.put("props", json.toString());
           
            getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
        }
    }
View Full Code Here

            return;
       
        Object key = null;
        String label = null;
       
        JSONObject json = writer.object();
       
        for (int i=0; i < filteredValues.size(); i++) {
            Object value = filteredValues.get(i);
           
            key = model.getPrimaryKey(value);
            label = model.getLabelFor(value);
           
            json.put(getDataSqueezer().squeeze(key), label );
        }
       
    }
View Full Code Here

       
        if (cycle.isRewinding()) {
            return;
        }
       
        JSONObject prop = new JSONObject();
        prop.put("widgetId", getClientId());
        prop.put("value", getValue());
        prop.put("mode", getMode());
        prop.put("minWidth", getMinWidth());
        prop.put("minHeight", getMinHeight());
        prop.put("doFade", getDoFade());
       
        Map parms = new HashMap();
        parms.put("component", this);
        parms.put("props", prop.toString());
       
        PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
        getScript().execute(this, 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("displayFormat", translator.getPattern(getPage().getLocale()));
        json.put("saveFormat", translator.getPattern(getPage().getLocale()));
       
        if (getValue() != null) {
            json.put("value", translator.formatRfc3339(getValue()));
        }
       
        json.put("disabled", isDisabled());
       
        Map parms = new HashMap();
        parms.put("clientId", getClientId());
        parms.put("props", json.toString());
        parms.put("widget", this);
       
        getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms);
    }
View Full Code Here

     */
    public void render(IMarkupWriter writer, IRequestCycle cycle)
    {
        // first configure dojo, has to happen before package include

        JSONObject dojoConfig = new JSONObject();

        // Debugging configuration , debugAtAlCosts causes the individual
        // .js files to included in the document head so that javascript errors
        // are able to resolve to the context of the file instead of just "dojo.js"

        dojoConfig.put("isDebug", _debug);

        if (_debugAtAllCosts)
            dojoConfig.put("debugAtAllCosts", _debugAtAllCosts);
        if (_debugContainerId != null)
            dojoConfig.put("debugContainerId", _debugContainerId);

        IPage page = cycle.getPage();

        // The key to resolving everything out of the asset service

        dojoConfig.put("baseRelativePath", _dojoPath.buildURL());

        if (page.hasFormComponents())
        {
            dojoConfig.put("preventBackButtonFix", _preventBackButtonFix);
        }
        dojoConfig.put("parseWidgets", _parseWidgets);

        // Supports setting up locale in dojo environment to match the requested page locale.
        // (for things that use these settings, like DropdownDatePicker / date parsing / etc..

        Locale locale = cycle.getPage().getLocale();

        dojoConfig.put("locale", locale.getLanguage().toLowerCase()
                                 + ((locale.getCountry() != null && locale.getCountry().trim().length() > 0)
                                    ? "-" + locale.getCountry().toLowerCase()
                                    : ""));

        // Write the required script includes and dojo.requires

        StringBuffer str = new StringBuffer("<script type=\"text/javascript\">");
        str.append("djConfig = ").append(dojoConfig.toString())
          .append(" </script>\n\n ");

        // include the core dojo.js package

        str.append("<script type=\"text/javascript\" src=\"")
View Full Code Here

       
        component.renderComponent(writer, cycle);
       
        verify();
       
        JSONObject json = writer.object();
       
        assertEquals(json.length(), 3);
        assertEquals(json.get("1"), "Simple 1");
        assertEquals(json.get("2"), "Simple 2");
        assertEquals(json.get("3"), "Simple 3");
    }
View Full Code Here

        writer.attribute("class", getUpdateElementClass());
        writer.end();

        // render javascript

        JSONObject json = null;
        String options = getOptions();

        try {

            json = options != null ? new JSONObject(options) : new JSONObject();

        } catch (ParseException ex)
        {
            throw new ApplicationRuntimeException(ScriptaculousMessages.invalidOptions(options, ex), this.getBinding("options").getLocation(), ex);
        }

        // bind onFailure client side function if not already defined

        if (!json.has("onFailure"))
        {
            json.put("onFailure", "tapestry.error");
        }

        if (!json.has("encoding"))
        {
            json.put("encoding", cycle.getEngine().getOutputEncoding());
        }

        Map parms = new HashMap();
        parms.put("inputId", getClientId());
        parms.put("updateId", getClientId() + "choices");
        parms.put("options", json.toString());

        Object[] specifiedParams = DirectLink.constructServiceParameters(getParameters());
        Object[] listenerParams = null;
        if (specifiedParams != null)
        {
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.