Package org.apache.tapestry.json

Examples of org.apache.tapestry.json.JSONObject


        boolean isAsync = isAsync() || update != null && update.size() > 0;

        if (!isAsync && type.equals(FormConstants.SUBMIT_NORMAL))
            return;
       
        JSONObject json = null;

        // build async URL to form if async

        if (isAsync)
        {
            IForm form = getForm();
           
            json = new JSONObject();
            json.put("async", Boolean.TRUE);
            json.put("json", isJson());
           
            DirectServiceParameter dsp = new DirectServiceParameter(form, null, this);
            json.put("url", getDirectService().getLink(true, dsp).getURL());
        }

        // only if not async - otherwise we have to stop the client side event to prevent normal form submission
        // within the submitbindings client side generated function
       
        if (!isAsync && !isParameterBound("onClick") && !isParameterBound("onclick"))
        {
            StringBuffer str = new StringBuffer();

            str.append("tapestry.form.").append(type);
            str.append("('").append(getForm().getClientId()).append("',");
            str.append("'").append(getName()).append("'");

            if (json != null)
                str.append(",").append(json.toString());

            str.append(")");
           
            writer.attribute("onClick", str.toString());
            return;
        }

        Map parms = new HashMap();
        parms.put("submit", this);
        parms.put("key", ScriptUtils.functionHash(type + this.hashCode()));
        parms.put("type", type);

        if (json != null)
            parms.put("parms", json.toString());
       
        PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
        getSubmitScript().execute(this, cycle, prs, parms);
    }
View Full Code Here


    {
        super.renderContribution(writer, cycle, context, field);

        String message = buildMessage(context, field, getMessageKey());

        JSONObject profile = context.getProfile();
        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);

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

        DecimalFormat format = getDecimalFormat(context.getLocale());

        String grouping = "";
        if (format.isGroupingUsed()) {

            grouping += ",separator:" + JSONObject.quote(format.getDecimalFormatSymbols().getGroupingSeparator());
            grouping += ",groupSize:" + format.getGroupingSize();
        } else {

            grouping += ",separator:\"\"";
        }

        cons.accumulate(field.getClientId(),
                        new JSONLiteral("[dojo.i18n.number.isReal,null,{"
                                        + "places:" + format.getMaximumFractionDigits() + ","
                                        + "decimal:"
                                        + JSONObject.quote(format.getDecimalFormatSymbols().getDecimalSeparator())
                                        + grouping
View Full Code Here

    }

    public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
            FormComponentContributorContext context, IFormComponent field)
    {
        JSONObject profile = context.getProfile();
       
        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);

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

        String maxString = getStringValue(context.getLocale(), field);
        String grouping = "";
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

    }

    public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
            FormComponentContributorContext context, IFormComponent field)
    {
        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.isText,{"
                        + "maxlength:" + _maxLength + "}]"));
       
View Full Code Here

    }

    public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
                                   FormComponentContributorContext context, IFormComponent field)
    {
        JSONObject profile = context.getProfile();

        if (!profile.has(ValidationConstants.CONSTRAINTS)) {
            profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
        }
        JSONObject cons = profile.getJSONObject(ValidationConstants.CONSTRAINTS);

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

        String minString = getStringValue(context.getLocale(), field);
        String grouping = "";
View Full Code Here

        _rewinding = cycle.isRewound(form);
        _allocatedIdIndex = 0;

        _pageRenderSupport = TapestryUtils.getOptionalPageRenderSupport(cycle);
        _profile = new JSONObject();
    }
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("Fred", "myfield");
       
        context.addInitializationScript(field, "dojo.require(\"dojo.validate.web\");");
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(context, null, ValidationStrings.INVALID_EMAIL,
                new Object[] { "Fred" }, "default\\message");
       
        replay();

        new Email().renderContribution(writer, cycle, context, field);

        verify();
       
        assertEquals("{\"constraints\":{\"myfield\":[[dojo.validate.isEmailAddress,false,true]]},"
                +"\"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();
       
        FormComponentContributorContext context = newMock(FormComponentContributorContext.class);
       
        IFormComponent field = newField("Fred", "barney");
       
        context.addInitializationScript(field, "dojo.require(\"dojo.validate.web\");");
       
        expect(context.getProfile()).andReturn(json);
       
        trainFormatMessage(
                context,
                "custom",
                ValidationStrings.INVALID_EMAIL,
                new Object[]
                { "Fred" },
                "custom message");
       
        replay();
       
        new Email("message=custom").renderContribution(writer, cycle, context, field);
       
        verify();
       
        assertEquals("{\"constraints\":{\"barney\":[[dojo.validate.isEmailAddress,false,true]]},"
                + "\"barney\":{\"constraints\":[\"custom message\"]}}",
                json.toString());
    }
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.