Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


    public void test_Render_Contribution()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
        IFormComponent field = newField("My Field", "myfield");

        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");

        Locale locale = Locale.FRANCE;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
       
        expect(context.getLocale()).andReturn(locale).atLeastOnce();
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_SMALL, new Object[]
        { "My Field", String.valueOf(new Double(20).doubleValue())}, "default message");
       
        replay();
       
        new Min("min=20").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":" +
                "[[tapestry.form.validation.greaterThanOrEqual,\"20.0\",{decimal:\",\"}]]}," +
                "\"myfield\":{\"constraints\":[\"default message\"]}}");
    }
View Full Code Here


   
    public void test_Render_Contribution_Custom_Message()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
        IFormComponent field = newField("My Field", "myfield");

        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");

        Locale locale = Locale.FRANCE;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
       
        expect(context.getLocale()).andReturn(locale).atLeastOnce();
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(
                context,
                "custom",
                ValidationStrings.VALUE_TOO_SMALL,
                new Object[]
                { "My Field", String.valueOf(new Double(20).doubleValue()) },
                "custom\\message");
       
        replay();
       
        new Min("min=20,message=custom").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":" +
                "[[tapestry.form.validation.greaterThanOrEqual,\"20.0\",{decimal:\",\"}]]}," +
                "\"myfield\":{\"constraints\":[\"custom\\\\message\"]}}");
    }
View Full Code Here

    public void test_Render_Contribution()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
       
        IFormComponent field = newField("My Field", "myfield");
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_LONG,
                new Object[] { new Integer(20), "My Field" }, "default\\message");
       
        replay();
       
        new MaxLength("maxLength=20").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals("{\"constraints\":{\"myfield\":[[dojo.validate.isText,{maxlength:20}]]},"
                +"\"myfield\":{\"constraints\":[\"default\\\\message\"]}}",
                json.toString());
    }
View Full Code Here

            IMarkupWriter writer, IRequestCycle cycle)
    {
        // we know this has to be a Required validator
        Required required = (Required)validator;
       
        JSONObject profile = context.getProfile();
       
        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
       
        required.accumulateProperty(cons, getClientId(),
                new JSONLiteral("[tapestry.form.validation.isPalleteSelected]"));
       
        required.accumulateProfileProperty(this, profile,
View Full Code Here

    public void test_Render_Contribution()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
        IFormComponent field = newField("My Field", "myfield");

        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");

        Locale locale = Locale.GERMAN;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);

        expect(context.getLocale()).andReturn(locale).anyTimes();
        expect(context.getProfile()).andReturn(json);

        trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_LARGE,
                           new Object[] {
                                   "My Field",
                                   new Double(20).toString()
                           }, "default message");

        replay();

        new Max("max=20").renderContribution(writer, cycle, context, field);

        verify();

        assertEquals(json.toString(),
                     "{\"constraints\":{\"myfield\":" +
                     "[[tapestry.form.validation.lessThanOrEqual,\"20.0\",{decimal:\",\"}]]}," +
                     "\"myfield\":{\"constraints\":[\"default message\"]}}");
    }
View Full Code Here

    public void test_Render_Contribution_Custom_Message()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
        IFormComponent field = newField("My Field", "myfield");

        context.addInitializationScript(field, "dojo.require(\"dojo.i18n.number\");");

        Locale locale = Locale.JAPAN;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);

        expect(context.getLocale()).andReturn(locale).anyTimes();
        expect(context.getProfile()).andReturn(json);

        trainFormatMessage(
                context,
                "custom",
                ValidationStrings.VALUE_TOO_LARGE,
                new Object[] {
                        "My Field",
                        new Double(20).toString()
                }, "custom\\message");

        replay();

        new Max("max=20,message=custom").renderContribution(writer, cycle, context, field);

        verify();

        assertEquals(json.toString(),
                     "{\"constraints\":{\"myfield\":" +
                     "[[tapestry.form.validation.lessThanOrEqual,\"20.0\",{decimal:\".\"}]]}," +
                     "\"myfield\":{\"constraints\":[\"custom\\\\message\"]}}");
    }
View Full Code Here

    public void test_Render_Contribution()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
       
        IFormComponent field = newField("My Field", "myfield");
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_SHORT,
                new Object[] { new Integer(25), "My Field" }, "default\\message");
       
        replay();
       
        new MinLength("minLength=25").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals("{\"constraints\":{\"myfield\":[[dojo.validate.isText,{minlength:25}]]},"
                +"\"myfield\":{\"constraints\":[\"default\\\\message\"]}}",
                json.toString());
    }
View Full Code Here

   
    public void test_Render_Contribution_Custom_Message()
    {
        IMarkupWriter writer = newWriter();
        IRequestCycle cycle = newCycle();
        JSONObject json = new JSONObject();
       
        IFormComponent field = newField("My Field", "customField");
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);

        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(
                context,
                "custom",
                ValidationStrings.VALUE_TOO_SHORT,
                new Object[] { new Integer(25), "My Field" },
                "custom\\message");
       
        replay();
       
        new MinLength("minLength=25,message=custom").renderContribution(
                writer,
                cycle,
                context,
                field);
       
        verify();
       
        assertEquals("{\"constraints\":{\"customField\":[[dojo.validate.isText,{minlength:25}]]},"
                + "\"customField\":{\"constraints\":[\"custom\\\\message\"]}}",
                json.toString());
    }
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 test_Json_Time()
    {
        long time = System.currentTimeMillis();

        JSONObject json = new JSONObject();
        json.put("time", time);

        assertEquals(json.toString(), "{\"time\":"+time+"}");
    }
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.