Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


    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);
       
        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.validate.isRealNumber,{places:0,decimal:\".\",separator:\",\"}]]}," +
                "\"myfield\":{\"constraints\":[\"invalid number 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);
       
        Locale locale = Locale.FRANCE;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
       
        expect(context.getLocale()).andReturn(locale);
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_SMALL, new Object[]
        { "My Field", new Double(20) }, "default message");
       
        replay();
       
        new Min("min=20").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":[[dojo.validate.isInRange," +
                "{min:20.0,decimal:\",\",separator:\""
                + symbols.getGroupingSeparator()
                + "\"}]]}," +
                "\"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();
       
        IFormComponent field = newField("My Field", "myfield");
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        Locale locale = Locale.FRANCE;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
       
        expect(context.getLocale()).andReturn(locale);
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(
                context,
                "custom",
                ValidationStrings.VALUE_TOO_SMALL,
                new Object[]
                { "My Field", new Double(20) },
                "custom\\message");
       
        replay();
       
        new Min("min=20,message=custom").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":[[dojo.validate.isInRange," +
                "{min:20.0,decimal:\",\",separator:\""
                + symbols.getGroupingSeparator()
                + "\"}]]},\"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);
       
        Locale locale = Locale.GERMAN;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
       
        expect(context.getLocale()).andReturn(locale);
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(context, null, ValidationStrings.VALUE_TOO_LARGE, new Object[]
        { "My Field", new Double(20) }, "default message");
       
        replay();
       
        new Max("max=20").renderContribution(writer, cycle, context, field);

        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":" +
                "[[dojo.validate.isInRange,{max:20.0,decimal:\",\",separator:\""
                + symbols.getGroupingSeparator()
                + "\"}]]}," +
                "\"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();
       
        IFormComponent field = newField("My Field", "myfield");
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        Locale locale = Locale.JAPAN;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
       
        expect(context.getLocale()).andReturn(locale);
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(
                context,
                "custom",
                ValidationStrings.VALUE_TOO_LARGE,
                new Object[]
                { "My Field", new Double(20) },
                "custom\\message");
       
        replay();
       
        new Max("max=20,message=custom").renderContribution(writer, cycle, context, field);

        verify();
       
        assertEquals(json.toString(),
                "{\"constraints\":{\"myfield\":[[dojo.validate.isInRange," +
                "{max:20.0,decimal:\".\",separator:\""
                + symbols.getGroupingSeparator()
                + "\"}]]}," +
                "\"myfield\":{\"constraints\":[\"custom\\\\message\"]}}");
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

       
        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

    public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
            FormComponentContributorContext context, IFormComponent field)
    {
        context.addInitializationScript(field, "dojo.require(\"dojo.validate.web\");");
       
        JSONObject profile = context.getProfile();
       
        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
       
        accumulateProperty(cons, field.getClientId(),
                new JSONLiteral("[dojo.validate.isEmailAddress,false,true]"));
       
        accumulateProfileProperty(field, profile,
View Full Code Here

    public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
            FormComponentContributorContext context, IFormComponent field)
    {
        String pattern = _matcher.getEscapedPatternString(_pattern);
       
        JSONObject profile = context.getProfile();
       
        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
       
        accumulateProperty(cons, field.getClientId(),
                new JSONLiteral("[tapestry.form.validation.isValidPattern,\""
                        + pattern + "\"]"));
       
View Full Code Here

        // with translators during client side validation as well
        DateTranslator translator = (DateTranslator) getFieldTranslator(field, DateTranslator.class);
        if (translator == null)
            return;
       
        JSONObject profile = context.getProfile();
       
        context.addInitializationScript(field, "dojo.require(\"tapestry.form.datetime\");");
       
        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);
       
        accumulateProperty(cons, field.getClientId(),
                new JSONLiteral("[tapestry.form.datetime.isValidDate,{"
                        + "min:"
                        + JSONObject.quote(translator.format(field, context.getLocale(), _minDate))
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.