Package org.apache.tapestry5.json

Examples of org.apache.tapestry5.json.JSONObject


        final Object result = callback.getResult();

        if (result != null)
            return result;

        return new JSONObject();
    }
View Full Code Here


    public String getInitialization()
    {
        Locale locale = threadLocale.getLocale();

        JSONObject spec = new JSONObject();

        DateFormatSymbols symbols = new DateFormatSymbols(locale);

        spec.put("months", new JSONArray((Object[])symbols.getMonths()));

        StringBuilder days = new StringBuilder();

        String[] weekdays = symbols.getWeekdays();

        Calendar c = Calendar.getInstance(locale);

        int firstDay = c.getFirstDayOfWeek();

        // DatePicker needs them in order from monday to sunday.

        for (int i = Calendar.MONDAY; i <= Calendar.SATURDAY; i++)
        {
            days.append(weekdays[i].substring(0, 1));
        }

        days.append(weekdays[Calendar.SUNDAY].substring(0, 1));

        spec.put("days", days.toString().toLowerCase(locale));

        // DatePicker expects 0 to be monday. Calendar defines SUNDAY as 1, MONDAY as 2, etc.

        spec.put("firstDay", firstDay == Calendar.SUNDAY ? 6 : firstDay - 2);

        // TODO: Skip localization if locale is English?

        return String.format("Tapestry.DateField.initLocalization(%s);", spec.toString(compactJSON));
    }
View Full Code Here

        this.environment = environment;
    }

    public void addZone(String clientId, String showFunctionName, String updateFunctionName)
    {
        JSONObject spec = new JSONObject("element", clientId);

        addFunction(spec, "show", showFunctionName);
        addFunction(spec, "update", updateFunctionName);

        FormSupport formSupport = environment.peek(FormSupport.class);

        if (formSupport != null)
        {
            JSONObject parameters = new JSONObject(RequestConstants.FORM_CLIENTID_PARAMETER, formSupport.getClientId(),
                    RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
            spec.put("parameters", parameters);
        }

        javascriptSupport.addInitializerCall("zone", spec);
View Full Code Here

            spec.put(key, functionName.toLowerCase());
    }

    public void linkZone(String linkId, String elementId, Link eventLink)
    {
        JSONObject spec = new JSONObject("linkId", linkId, "zoneId", elementId, "url", eventLink.toURI());

        javascriptSupport.addInitializerCall("linkZone", spec);
    }
View Full Code Here

        addFormFragment(clientId, false, showFunctionName, hideFunctionName, null);
    }

    public void addFormFragment(String clientId, boolean alwaysSubmit, String showFunctionName, String hideFunctionName, String visibilityBoundFunctionName)
    {
        JSONObject spec = new JSONObject("element", clientId);

        addFunction(spec, "show", showFunctionName);
        addFunction(spec, "hide", hideFunctionName);

        if (visibilityBoundFunctionName != null)
            spec.put("bound", new JSONLiteral(visibilityBoundFunctionName));

        if (alwaysSubmit)
            spec.put("alwaysSubmit", true);

        javascriptSupport.addInitializerCall("formFragment", spec);
    }
View Full Code Here

        javascriptSupport.addInitializerCall("formFragment", spec);
    }

    public void addFormInjector(String clientId, Link link, InsertPosition insertPosition, String showFunctionName)
    {
        JSONObject spec = new JSONObject("element", clientId, "url", link.toURI());

        if (insertPosition == InsertPosition.BELOW)
            spec.put("below", true);

        addFunction(spec, "show", showFunctionName);

        // Always has at least two properties.
View Full Code Here

      ZoneRefresh zoneRefresh = new ZoneRefresh(context, resources, javaScriptSupport, zone);
     
      expect(resources.createEventLink("zoneRefresh", context)).andReturn(link);
      expect(link.toAbsoluteURI()).andReturn("mylink");
     
      JSONObject params = new JSONObject();
      params.put("period", 0);
      params.put("id", zone.getClientId());
      params.put("URL", "mylink");
      javaScriptSupport.addInitializerCall(InitializationPriority.LATE, "zoneRefresh", params);
     
      replay();
     
      zoneRefresh.addJavaScript();
View Full Code Here

        writer.element("div", "id", clientId);
        resources.renderInformalParameters(writer);
        writer.end();

        JSONObject spec = new JSONObject("id", clientId,
                "dismissURL", resources.createEventLink("dismiss").toURI(),
                "dismissText", dismissText);

        javaScriptSupport.addInitializerCall(InitializationPriority.EARLY, "alertManager", spec);
View Full Code Here

            {
                storage.dismissAll();
            }
        }

        return new JSONObject();
    }
View Full Code Here

    @Test
    public void partial_mode_add_script()
    {
        DocumentLinker linker = mockDocumentLinker();

        linker.setInitialization(InitializationPriority.NORMAL, new JSONObject(
                "{ 'evalScript' : [ 'doSomething();' ] }"));

        replay();

        JavaScriptSupportImpl jss = new JavaScriptSupportImpl(linker, null, null, new IdAllocator(), true);
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.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.