Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


    public void test_Render_Contribution()
    {
        NumberTranslator translator = new NumberTranslator();
        IFormComponent field = newField("Number Field", "numberField", 1);
       
        JSONObject json = new JSONObject();
       
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        expect(context.getProfile()).andReturn(json);
        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");
       
        trainGetLocale(context, Locale.ENGLISH);
       
        trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER,
                new Object[] { "Number Field", "#" }, "invalid number message");
       
        replay();
       
        translator.renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"numberField\":" +
                "[[dojo.i18n.number.isReal,null,{places:0,decimal:\".\",separator:\"\"}]]}," +
                "\"numberField\":{\"constraints\":[\"invalid number message\"]}}");
    }
View Full Code Here


    {
        NumberTranslator translator = new NumberTranslator();
        translator.setPattern("###,##");
        IFormComponent field = newField("Number Field", "numberField", 1);

        JSONObject json = new JSONObject();

        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();

        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);

        expect(context.getProfile()).andReturn(json);
        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");

        trainGetLocale(context, Locale.US);

        trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER, new String[] { "Number Field", "#,##" },
                          "invalid number message");

        replay();

        translator.renderContribution(writer, cycle, context, field);

        verify();

        assertEquals(json.toString(),
                "{\"constraints\":{\"numberField\":" +
                "[[dojo.i18n.number.isReal,null," +
                "{places:0,decimal:\".\",separator:\",\",groupSize:2}]]}," +
                "\"numberField\":{\"constraints\":[\"invalid number message\"]}}");
    }
View Full Code Here

        String messageOverride = "You entered a bunk value for {0}. I should look like {1}. Watch out for ''this''!";

        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
       
        JSONObject json = new JSONObject();
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);

        expect(context.getProfile()).andReturn(json);
        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");
       
        trainGetLocale(context, Locale.ENGLISH);
       
        trainBuildMessage(
                context,
                messageOverride,
                ValidationStrings.INVALID_NUMBER,
                new Object[] { "Number Field", "#" },
                "Blah Blah 'Field Name' Blah.");
       
        replay();
       
        translator.setMessage(messageOverride);

        translator.renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":[[dojo.i18n.number.isReal,null," +
                "{places:0,decimal:\".\",separator:\"\"}]]}," +
                "\"myfield\":{\"constraints\":[\"Blah Blah 'Field Name' Blah.\"]}}");
    }
View Full Code Here

    public void test_Trim_Render_Contribution()
    {
        IFormComponent field = newField("Number Field", "myfield", 2);
       
        NumberTranslator translator = new NumberTranslator();
        JSONObject json = new JSONObject();
       
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        expect(context.getProfile()).andReturn(json);
        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");
       
        trainGetLocale(context, Locale.ENGLISH);
       
        trainBuildMessage(context, null, ValidationStrings.INVALID_NUMBER, new Object[]
        { "Number Field", "#" }, "invalid number message");
       
        expect(context.getProfile()).andReturn(json);
       
        replay();

        translator.setTrim(true);
       
        translator.renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"trim\":[\"myfield\"]," +
                "\"constraints\":{\"myfield\":[[dojo.i18n.number.isReal,null," +
                "{places:0,decimal:\".\",separator:\"\"}]]}," +
                "\"myfield\":{\"constraints\":[\"invalid number message\"]}}");
    }
View Full Code Here

     */
    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

     */
    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"

        if (_debug)
        {
            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();

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

        if (isLocaleSupported(localeStr))
        {
            dojoConfig.put("locale", localeStr);
        }

        // Write the required script includes and dojo.requires

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

        // include the core dojo.js package

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", key != null ? 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());
            json.put("followScroll", getFollowScroll());
            json.put("closeOnBackgroundClick", getCloseOnBackgroundClick());
            json.put("blockDuration", getBlockDuration());
            json.put("lifeTime", getLifeTime());
            json.put("toggle", getToggle());
            json.put("toggleDuration", getToggleDuration());

            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

        optStr.append("]");
       
        // now create widget parms

        JSONObject json = new JSONObject();
        json.put("inputNodeId", getClientId());
        json.put("optionValues", new JSONLiteral(optStr.toString()));

        if (selectedIndex > -1)
        {
            json.put("selectedIndex", selectedIndex);
        }

        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

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.