Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


    @Test
    public void add_script_and_update()
    {
        PartialRenderPageRenderSupport prs = new PartialRenderPageRenderSupport();

        JSONObject reply = new JSONObject();


        prs.update(reply);


        assertEquals(reply.toString(), "{}");


        prs.addScript("x = %d;", 10);

        prs.update(reply);

        assertEquals(reply.getString("script"), "x = 10;");
    }
View Full Code Here


        writer.end();

        Link link = _resources.createActionLink(EVENT_NAME, false);


        JSONObject config = new JSONObject();
        config.put("paramName", PARAM_NAME);
        config.put("indicator", loaderId);

        if (_resources.isBound("minChars")) config.put("minChars", _minChars);

        if (_resources.isBound("frequency")) config.put("frequency", _frequency);

        if (_resources.isBound("tokens"))
        {
            for (int i = 0; i < _tokens.length(); i++)
            {
                config.accumulate("tokens", _tokens.substring(i, i + 1));
            }
        }

        // Let subclasses do more.
        configure(config);
View Full Code Here

        support.addValidation(fred, "maxlength", "Up to 10 characters", 10);

        verify();


        JSONObject validations = support.getValidations();

        // Tip-toe around the fact that the order of the keys is JDK specific.

        assertEquals(CollectionFactory.newSet(validations.keys()), CollectionFactory.newSet("fred", "barney"));

        assertEquals(validations.get("fred").toString(), "[[\"maxlength\",\"Up to 10 characters\",10]]");
        assertEquals(validations.get("barney").toString(),
                     "[[\"required\",\"Who can live without Barney?\"],[\"email\",\"You know, an e-mail address.\"]]");


    }
View Full Code Here

        writer.end(); // img
        writer.end(); // button

        // The setup parameters passed to Calendar.setup():

        JSONObject setup = new JSONObject();

        setup.put("inputField", clientId);
        setup.put("ifFormat", _format);
        setup.put("button", triggerId);

        // Let subclasses do more.

        configure(setup);
View Full Code Here

        writer.end();

        Link link = _resources.createActionLink(EVENT_NAME, false);


        JSONObject config = new JSONObject();
        config.put("paramName", PARAM_NAME);
        config.put("indicator", loaderId);

        if (_resources.isBound("minChars")) config.put("minChars", _minChars);

        if (_resources.isBound("frequency")) config.put("frequency", _frequency);

        if (_resources.isBound("tokens"))
        {
            for (int i = 0; i < _tokens.length(); i++)
            {
                config.accumulate("tokens", _tokens.substring(i, i + 1));
            }
        }

        _pageRenderSupport.addScript("new Ajax.Autocompleter('%s', '%s', '%s', %s);", id, menuId, link, config);
    }
View Full Code Here

        writer.end(); // img
        writer.end(); // button

        // The setup parameters passed to Calendar.setup():

        JSONObject setup = new JSONObject();

        setup.put("inputField", clientId);
        setup.put("ifFormat", _format);
        setup.put("button", triggerId);

        // Let subclasses do more.

        configure(setup);
View Full Code Here

        ContentType contentType = new ContentType("text/javascript");

        MarkupWriter writer = _factory.newMarkupWriter();

        JSONObject reply = new JSONObject();

        // ... and here, the pipeline eventually reaches the PRQ to let it render the root render command.

        _partialMarkupRenderer.renderMarkup(writer, reply);
View Full Code Here

        if (exceptionHolder.hasValue()) throw exceptionHolder.get();

        if (holder.hasValue()) return;

        JSONObject reply = new JSONObject();

        _resultProcessor.processComponentEvent(reply, null, null);

    }
View Full Code Here

    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);
       
        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.validate.isRealNumber," +
                "{places:0,decimal:\".\",separator:\",\"}]]},\"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);
       
        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.validate.isRealNumber," +
                "{places:0,decimal:\".\",separator:\",\"}]]},\"myfield\":" +
                "{\"constraints\":[\"Blah Blah \'Field Name\' Blah.\"]}}");
    }
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.