Package org.apache.tapestry

Examples of org.apache.tapestry.NestedMarkupWriter


    public void testSimpleRenderWithDeferredRunnable()
    {
        MockControl writerc = newControl(IMarkupWriter.class);
        IMarkupWriter writer = (IMarkupWriter) writerc.getMock();

        NestedMarkupWriter nested = newNestedWriter();

        MockControl cyclec = newControl(IRequestCycle.class);
        IRequestCycle cycle = (IRequestCycle) cyclec.getMock();

        MockForm form = new MockForm();

        cycle.isRewound(form);
        cyclec.setReturnValue(false);

        replayControls();

        final FormSupport fs = new FormSupportImpl(writer, cycle, form);

        verifyControls();

        IRender body = new IRender()
        {

            public void render(final IMarkupWriter writer, IRequestCycle cycle)
            {
                fs.addDeferredRunnable(new Runnable()
                {

                    public void run()
                    {
                        writer.print("DEFERRED");
                    }

                });
            }

        };

        form.setBody(body);

        MockControl linkc = newControl(ILink.class);
        ILink link = (ILink) linkc.getMock();

        IRender render = (IRender) newMock(IRender.class);

        link.getParameterNames();
        linkc.setReturnValue(new String[]
        { "service" });

        link.getParameterValues("service");
        linkc.setReturnValue(new String[]
        { "fred" });

        writer.getNestedWriter();
        writerc.setReturnValue(nested);

        link.getURL(null, false);
        linkc.setReturnValue("/app");

        writer.begin("form");
        writer.attribute("method", "post");
        writer.attribute("action", "/app");

        writer.attribute("name", "myform");

        render.render(writer, cycle);

        writer.println();

        trainHidden(writer, "formids", "");
        trainHidden(writer, "service", "fred");

        // EasyMock can't fully verify that this gets called at the right moment, nor can we truly
        // prove (well, except by looking at the code), that the deferred runnables execute at the
        // right time.

        nested.print("DEFERRED");

        nested.close();

        writer.end();

        replayControls();
View Full Code Here


    public void testSimpleSubmitEventHandler()
    {
        MockControl writerc = newControl(IMarkupWriter.class);
        IMarkupWriter writer = (IMarkupWriter) writerc.getMock();

        NestedMarkupWriter nested = newNestedWriter();

        MockControl cyclec = newControl(IRequestCycle.class);
        IRequestCycle cycle = (IRequestCycle) cyclec.getMock();

        MockForm form = new MockForm();

        cycle.isRewound(form);
        cyclec.setReturnValue(false);

        replayControls();

        final FormSupport fs = new FormSupportImpl(writer, cycle, form);

        verifyControls();

        form.setBody(new IRender()
        {
            public void render(IMarkupWriter writer, IRequestCycle cycle)
            {
                fs.addEventHandler(FormEventType.SUBMIT, "mySubmit");
            }
        });

        MockControl linkc = newControl(ILink.class);
        ILink link = (ILink) linkc.getMock();

        IRender render = (IRender) newMock(IRender.class);

        link.getParameterNames();
        linkc.setReturnValue(new String[]
        { "service" });

        link.getParameterValues("service");
        linkc.setReturnValue(new String[]
        { "fred" });

        writer.getNestedWriter();
        writerc.setReturnValue(nested);

        link.getURL(null, false);
        linkc.setReturnValue("/app");

        writer.begin("form");
        writer.attribute("method", "post");
        writer.attribute("action", "/app");

        writer.attribute("name", "myform");

        render.render(writer, cycle);

        writer.println();

        trainHidden(writer, "formids", "");
        trainHidden(writer, "service", "fred");

        nested.close();

        writer.end();

        trainForPageSupport(cyclec, cycle, "document.myform.onsubmit = mySubmit;\n");
View Full Code Here

        // write out captured content
        Iterator keys = _writers.keySet().iterator();
        while (keys.hasNext()) {
           
            String key = (String)keys.next();
            NestedMarkupWriter nw = (NestedMarkupWriter)_writers.get(key);
           
            nw.end();
           
            if (!isScriptWriter(key))
                _writer.printRaw(ScriptUtils.ensureValidScriptTags(nw.getBuffer()));
            else
                _writer.printRaw(nw.getBuffer());
        }
       
        //end response
        _writer.printRaw("</ajax-response>");
        _writer.flush();
View Full Code Here

        IRender render = newMock(IRender.class);

        IComponent comp1 = newMock(IComponent.class);
        IRequestCycle cycle = newMock(IRequestCycle.class);
        IMarkupWriter writer = newMock(IMarkupWriter.class);
        NestedMarkupWriter nested = newMock(NestedMarkupWriter.class);

        Infrastructure infra = newMock(Infrastructure.class);

        List parts = new ArrayList();
        parts.add("id1");

        DojoAjaxResponseBuilder builder = new DojoAjaxResponseBuilder(cycle, writer, parts);

        render.render(NullWriter.getSharedInstance(), cycle);

        expect(comp1.getClientId()).andReturn("id1").anyTimes();
        expect(comp1.peekClientId()).andReturn("id1").anyTimes();
        expect(cycle.getInfrastructure()).andReturn(infra);
        expect(infra.getOutputEncoding()).andReturn("UTF-8");

        writer.printRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        writer.printRaw("<!DOCTYPE html "
                        + "PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
                        + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" [" + NEWLINE
                        + "<!ENTITY nbsp '&#160;'>" + NEWLINE
                        + "]>" + NEWLINE);
        writer.printRaw("<ajax-response>");

        expect(writer.getNestedWriter()).andReturn(nested);

        nested.begin("response");
        nested.attribute("id", "id1");
        nested.attribute("type", ResponseBuilder.ELEMENT_TYPE);

        comp1.render(nested, cycle);

        replay();
View Full Code Here

        IPage page = newMock(IPage.class);
        checkOrder(page, false);

        IRequestCycle cycle = newMock(IRequestCycle.class);
        IMarkupWriter writer = newMock(IMarkupWriter.class);
        NestedMarkupWriter nwriter = newNestedWriter();

        ILink link = newMock(ILink.class);

        RequestLocaleManager rlm = newMock(RequestLocaleManager.class);
        MarkupWriterSource mrs = newMock(MarkupWriterSource.class);
        WebResponse resp = newMock(WebResponse.class);
        AssetFactory assetFactory = newMock(AssetFactory.class);
        IEngineService pageService = newEngineService();

        List errorPages = new ArrayList();

        List parts = new ArrayList();
        parts.add("id1");

        DojoAjaxResponseBuilder builder =  new DojoAjaxResponseBuilder(cycle, rlm, mrs, resp, errorPages, assetFactory, "", pageService);

        builder.setWriter(writer);

        expect(page.getPageName()).andReturn("RequestPage").anyTimes();
        expect(cycle.getParameter(ServiceConstants.PAGE)).andReturn("anotherPage").anyTimes();

        expect(writer.getNestedWriter()).andReturn(nwriter);
        nwriter.begin("response");
        nwriter.attribute("type", ResponseBuilder.PAGE_TYPE);

        expect(pageService.getLink(true, "RequestPage")).andReturn(link);
        expect(link.getAbsoluteURL()).andReturn("/new/url");

        nwriter.attribute("url", "/new/url");

        replay();

        builder.render(null, page, cycle);
View Full Code Here

        IPage page = newMock(IPage.class);
        checkOrder(page, false);
        IRequestCycle cycle = newMock(IRequestCycle.class);
        Infrastructure infra = newMock(Infrastructure.class);
        IMarkupWriter writer = newBufferWriter();
        NestedMarkupWriter nwriter = newNestedWriter();

        ILink link = newMock(ILink.class);
        Location l = newLocation();

        RequestLocaleManager rlm = newMock(RequestLocaleManager.class);
View Full Code Here

    public void testComplexRender()
    {
        MockControl writerc = newControl(IMarkupWriter.class);
        IMarkupWriter writer = (IMarkupWriter) writerc.getMock();

        NestedMarkupWriter nested = newNestedWriter();

        MockControl cyclec = newControl(IRequestCycle.class);
        IRequestCycle cycle = (IRequestCycle) cyclec.getMock();

        MockControl enginec = newControl(IEngine.class);
        IEngine engine = (IEngine) enginec.getMock();

        MockControl delegatec = newControl(IValidationDelegate.class);
        IValidationDelegate delegate = (IValidationDelegate) delegatec.getMock();

        MockForm form = new MockForm(delegate);

        cycle.isRewound(form);
        cyclec.setReturnValue(false);

        cycle.getEngine();
        cyclec.setReturnValue(engine);

        engine.getClassResolver();
        enginec.setReturnValue(getClassResolver());

        MockControl supportc = newControl(PageRenderSupport.class);
        PageRenderSupport support = (PageRenderSupport) supportc.getMock();

        trainGetPageRenderSupport(cyclec, cycle, support);

        replayControls();

        final FormSupport fs = new FormSupportImpl(writer, cycle, form);

        verifyControls();

        final IFormComponent barney1 = newFormComponent("barney", "barney");
        final IFormComponent wilma = newFormComponent("wilma", "wilma");
        final IFormComponent barney2 = newFormComponent("barney", "barney$0");

        IRender body = newComponentsRenderBody(fs, new IFormComponent[]
        { barney1, wilma, barney2 }, nested);

        form.setBody(body);

        MockControl linkc = newControl(ILink.class);
        ILink link = (ILink) linkc.getMock();

        IRender render = (IRender) newMock(IRender.class);

        support.addExternalScript(new ClasspathResource(getClassResolver(),
                "/org/apache/tapestry/form/Form.js"));

        support
                .addInitializationScript("var myform_events = new FormEventManager(document.myform);");

        link.getParameterNames();
        linkc.setReturnValue(new String[]
        { "service" });

        link.getParameterValues("service");
        linkc.setReturnValue(new String[]
        { "fred" });

        writer.getNestedWriter();
        writerc.setReturnValue(nested);

        link.getURL(null, false);
        linkc.setReturnValue("/app");

        writer.begin("form");
        writer.attribute("method", "post");
        writer.attribute("action", "/app");

        writer.attribute("name", "myform");

        render.render(writer, cycle);

        writer.println();

        trainHidden(writer, "formids", "barney,wilma,barney$0");
        trainHidden(writer, "service", "fred");
        trainHidden(writer, "submitmode", "");

        nested.close();

        writer.end();

        trainGetFocusField(delegatec, delegate, "wilma");
        trainGetFieldFocus(cyclec, cycle, null);
View Full Code Here

    public void testComplexSubmitEventHandler()
    {
        MockControl writerc = newControl(IMarkupWriter.class);
        IMarkupWriter writer = (IMarkupWriter) writerc.getMock();

        NestedMarkupWriter nested = newNestedWriter();

        MockControl cyclec = newControl(IRequestCycle.class);
        IRequestCycle cycle = (IRequestCycle) cyclec.getMock();

        MockControl enginec = newControl(IEngine.class);
        IEngine engine = (IEngine) enginec.getMock();

        MockControl delegatec = newControl(IValidationDelegate.class);
        IValidationDelegate delegate = (IValidationDelegate) delegatec.getMock();

        MockForm form = new MockForm(delegate);

        cycle.isRewound(form);
        cyclec.setReturnValue(false);

        cycle.getEngine();
        cyclec.setReturnValue(engine);

        engine.getClassResolver();
        enginec.setReturnValue(getClassResolver());

        MockControl supportc = newControl(PageRenderSupport.class);
        PageRenderSupport support = (PageRenderSupport) supportc.getMock();

        trainGetPageRenderSupport(cyclec, cycle, support);

        replayControls();

        final FormSupport fs = new FormSupportImpl(writer, cycle, form);

        verifyControls();

        form.setBody(new IRender()
        {
            public void render(IMarkupWriter writer, IRequestCycle cycle)
            {
                fs.addEventHandler(FormEventType.SUBMIT, "mySubmit1");
                fs.addEventHandler(FormEventType.SUBMIT, "mySubmit2");
                fs.addEventHandler(FormEventType.SUBMIT, "mySubmit3");
            }
        });

        MockControl linkc = newControl(ILink.class);
        ILink link = (ILink) linkc.getMock();

        IRender render = (IRender) newMock(IRender.class);

        support.addExternalScript(new ClasspathResource(getClassResolver(),
                "/org/apache/tapestry/form/Form.js"));

        support
                .addInitializationScript("var myform_events = new FormEventManager(document.myform);");

        link.getParameterNames();
        linkc.setReturnValue(new String[]
        { "service" });

        link.getParameterValues("service");
        linkc.setReturnValue(new String[]
        { "fred" });

        writer.getNestedWriter();
        writerc.setReturnValue(nested);

        link.getURL(null, false);
        linkc.setReturnValue("/app");

        writer.begin("form");
        writer.attribute("method", "post");
        writer.attribute("action", "/app");

        writer.attribute("name", "myform");

        render.render(writer, cycle);

        writer.println();

        trainHidden(writer, "formids", "");
        trainHidden(writer, "service", "fred");
        trainHidden(writer, "submitmode", "");

        nested.close();

        writer.end();

        support
                .addInitializationScript("myform_events.addSubmitListener(function (event)\n{\n  mySubmit1();\n  mySubmit2();\n  mySubmit3();\n});\n");
View Full Code Here

    public void testEncodingType()
    {
        MockControl writerc = newControl(IMarkupWriter.class);
        IMarkupWriter writer = (IMarkupWriter) writerc.getMock();

        NestedMarkupWriter nested = newNestedWriter();

        MockControl cyclec = newControl(IRequestCycle.class);
        IRequestCycle cycle = (IRequestCycle) cyclec.getMock();

        MockControl enginec = newControl(IEngine.class);
        IEngine engine = (IEngine) enginec.getMock();

        MockControl delegatec = newControl(IValidationDelegate.class);
        IValidationDelegate delegate = (IValidationDelegate) delegatec.getMock();

        MockForm form = new MockForm(delegate);

        cycle.isRewound(form);
        cyclec.setReturnValue(false);

        cycle.getEngine();
        cyclec.setReturnValue(engine);

        engine.getClassResolver();
        enginec.setReturnValue(getClassResolver());

        MockControl supportc = newControl(PageRenderSupport.class);
        PageRenderSupport support = (PageRenderSupport) supportc.getMock();

        trainGetPageRenderSupport(cyclec, cycle, support);

        replayControls();

        final FormSupport fs = new FormSupportImpl(writer, cycle, form);

        verifyControls();

        form.setBody(new IRender()
        {
            public void render(IMarkupWriter writer, IRequestCycle cycle)
            {
                fs.setEncodingType("foo/bar");
            }
        });

        MockControl linkc = newControl(ILink.class);
        ILink link = (ILink) linkc.getMock();

        IRender render = (IRender) newMock(IRender.class);

        support.addExternalScript(new ClasspathResource(getClassResolver(),
                "/org/apache/tapestry/form/Form.js"));

        support
                .addInitializationScript("var myform_events = new FormEventManager(document.myform);");

        link.getParameterNames();
        linkc.setReturnValue(new String[]
        { "service" });

        link.getParameterValues("service");
        linkc.setReturnValue(new String[]
        { "fred" });

        writer.getNestedWriter();
        writerc.setReturnValue(nested);

        link.getURL(null, false);
        linkc.setReturnValue("/app");

        writer.begin("form");
        writer.attribute("method", "post");
        writer.attribute("action", "/app");
        writer.attribute("name", "myform");
        writer.attribute("enctype", "foo/bar");

        render.render(writer, cycle);

        writer.println();

        trainHidden(writer, "formids", "");
        trainHidden(writer, "service", "fred");
        trainHidden(writer, "submitmode", "");

        nested.close();

        writer.end();

        trainGetFocusField(delegatec, delegate, null);
View Full Code Here

    public void testHiddenValues()
    {
        MockControl writerc = newControl(IMarkupWriter.class);
        IMarkupWriter writer = (IMarkupWriter) writerc.getMock();

        NestedMarkupWriter nested = newNestedWriter();

        MockControl cyclec = newControl(IRequestCycle.class);
        IRequestCycle cycle = (IRequestCycle) cyclec.getMock();

        MockControl enginec = newControl(IEngine.class);
        IEngine engine = (IEngine) enginec.getMock();

        MockControl delegatec = newControl(IValidationDelegate.class);
        IValidationDelegate delegate = (IValidationDelegate) delegatec.getMock();

        MockForm form = new MockForm(delegate);

        cycle.isRewound(form);
        cyclec.setReturnValue(false);

        cycle.getEngine();
        cyclec.setReturnValue(engine);

        engine.getClassResolver();
        enginec.setReturnValue(getClassResolver());

        MockControl supportc = newControl(PageRenderSupport.class);
        PageRenderSupport support = (PageRenderSupport) supportc.getMock();

        trainGetPageRenderSupport(cyclec, cycle, support);

        replayControls();

        final FormSupport fs = new FormSupportImpl(writer, cycle, form);

        verifyControls();

        form.setBody(new IRender()
        {
            public void render(IMarkupWriter writer, IRequestCycle cycle)
            {
                fs.addHiddenValue("hidden1", "value1");
                fs.addHiddenValue("hidden2", "id2", "value2");
            }
        });

        MockControl linkc = newControl(ILink.class);
        ILink link = (ILink) linkc.getMock();

        IRender render = (IRender) newMock(IRender.class);

        support.addExternalScript(new ClasspathResource(getClassResolver(),
                "/org/apache/tapestry/form/Form.js"));

        support
                .addInitializationScript("var myform_events = new FormEventManager(document.myform);");

        link.getParameterNames();
        linkc.setReturnValue(new String[]
        { "service" });

        link.getParameterValues("service");
        linkc.setReturnValue(new String[]
        { "fred" });

        writer.getNestedWriter();
        writerc.setReturnValue(nested);

        link.getURL(null, false);
        linkc.setReturnValue("/app");

        writer.begin("form");
        writer.attribute("method", "post");
        writer.attribute("action", "/app");

        writer.attribute("name", "myform");

        render.render(writer, cycle);

        writer.println();

        trainHidden(writer, "formids", "");
        trainHidden(writer, "service", "fred");
        trainHidden(writer, "submitmode", "");
        trainHidden(writer, "hidden1", "value1");
        trainHidden(writer, "hidden2", "id2", "value2");

        nested.close();

        writer.end();

        trainGetFocusField(delegatec, delegate, null);
View Full Code Here

TOP

Related Classes of org.apache.tapestry.NestedMarkupWriter

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.