Package org.apache.tapestry

Examples of org.apache.tapestry.IMarkupWriter


        if (Tapestry.isNonBlank(title))
            writer.attribute("title", title);

        renderInformalParameters(writer, cycle);

        IMarkupWriter nestedWriter = writer.getNestedWriter();

        renderBody(nestedWriter, cycle);

        nestedWriter.close();

        writer.end();

        cycle.removeAttribute(ATTRIBUTE_NAME);
    }
View Full Code Here


        // Commit all changes and ignore further changes.

        IPage page = cycle.getPage();

        IMarkupWriter writer = page.getResponseWriter(output);

        output.setContentType(writer.getContentType());

        boolean discard = true;

        try
        {
            cycle.renderPage(writer);

            discard = false;
        }
        finally
        {
            // Closing the writer closes its PrintWriter and a whole stack of java.io objects,
            // which tend to stream a lot of output that eventually hits the
            // ResponseOutputStream.  If we are discarding output anyway (due to an exception
            // getting thrown during the render), we can save ourselves some trouble
            // by ignoring it.

            if (discard)
                output.setDiscard(true);

            writer.close();

            if (discard)
                output.setDiscard(false);
        }
View Full Code Here

        ILink link = getLink(cycle, actionId);

        // When rendering, use a nested writer so that an embedded Upload
        // component can force the encoding type.

        IMarkupWriter nested = writer.getNestedWriter();

        renderBody(nested, cycle);

        if (renderForm)
        {
            writeAttributes(writer, link);

            renderInformalParameters(writer, cycle);
            writer.println();
        }

        // Write the hidden's, or at least, reserve the query parameters
        // required by the Gesture.

        writeLinkParameters(writer, link, !renderForm);

        if (renderForm)
        {
            // What's this for?  It's part of checking for stale links. 
            // We record the list of allocated ids.
            // On rewind, we check that the stored list against which
            // ids were allocated.  If the persistent state of the page or
            // application changed between render (previous request cycle)
            // and rewind (current request cycle), then the list
            // of ids will change as well.

            writeHiddenField(writer, _name, buildAllocatedIdList());
            writeHiddenValues(writer);

            nested.close();

            writer.end(getTag());

            // Write out event handlers collected during the rendering.
View Full Code Here

        boolean rewinding = form.isRewinding();

        String name = form.getElementId(this);

        IMarkupWriter wrappedWriter;

        if (cycle.getAttribute(ATTRIBUTE_NAME) != null)
            throw new ApplicationRuntimeException(
                Tapestry.getMessage("LinkSubmit.may-not-nest"),
                this,
                null,
                null);

        cycle.setAttribute(ATTRIBUTE_NAME, this);

        boolean disabled = isDisabled();
        if (!disabled)
        {
            if (!rewinding)
            {
                Body body = Body.get(cycle);

        if (body == null)
            throw new ApplicationRuntimeException(
                Tapestry.format("must-be-contained-by-body", "LinkSubmit"),
                this,
                null,
                null);
                       
                // make sure the submit function is on the page (once)
                if (cycle.getAttribute(ATTRIBUTE_FUNCTION_NAME) == null)
                {
                    body.addBodyScript(
                        "function submitLink(form, elementId) { form._linkSubmit.value = elementId; if (form.onsubmit == null || form.onsubmit()) form.submit(); }");
                    cycle.setAttribute(ATTRIBUTE_FUNCTION_NAME, this);
                }

                // one hidden field per form:
                String formHiddenFieldAttributeName = ATTRIBUTE_FUNCTION_NAME + formName;
                if (cycle.getAttribute(formHiddenFieldAttributeName) == null)
                {
                  body.addInitializationScript("document." + formName + "._linkSubmit.value = null;");
                    writer.beginEmpty("input");
                    writer.attribute("type", "hidden");
                    writer.attribute("name", "_linkSubmit");
                    cycle.setAttribute(formHiddenFieldAttributeName, this);
                }
            }
            else
            {
                // How to know which Submit link was actually
                // clicked?  When submitted, it sets its elementId into a hidden field

                String value = cycle.getRequestContext().getParameter("_linkSubmit");

                // If the value isn't the elementId of this component, then this link wasn't
                // selected.

                if (value != null && value.equals(name))
                {
                    IBinding selectedBinding = getSelectedBinding();
                    if (selectedBinding != null)
                        selectedBinding.setObject(getTag());
                    IActionListener listener = getListener();
                    if (listener != null)
                        listener.actionTriggered(this, cycle);
                }
            }

            writer.begin("a");
            writer.attribute(
                "href",
                "javascript:submitLink(document." + formName + ",\"" + name + "\");");

            // Allow the wrapped components a chance to render.
            // Along the way, they may interact with this component
            // and cause the name variable to get set.

            wrappedWriter = writer.getNestedWriter();
        }
        else
            wrappedWriter = writer;

        renderBody(wrappedWriter, cycle);

        if (!disabled)
        {
            // Generate additional attributes from informal parameters.

            renderInformalParameters(writer, cycle);

            // Dump in HTML provided by wrapped components

            wrappedWriter.close();

            // Close the <a> tag

            writer.end();
        }
View Full Code Here

    public static final ILinkRenderer SHARED_INSTANCE = new DefaultLinkRenderer();

    public void renderLink(IMarkupWriter writer, IRequestCycle cycle, ILinkComponent linkComponent)
    {
        IMarkupWriter wrappedWriter = null;

        if (cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME) != null)
            throw new ApplicationRuntimeException(
                Tapestry.getMessage("AbstractLinkComponent.no-nesting"),
                linkComponent,
                null,
                null);

        cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME, linkComponent);

        boolean hasBody = getHasBody();

        boolean disabled = linkComponent.isDisabled();

        if (!disabled)
        {
            ILink l = linkComponent.getLink(cycle);

            if (hasBody)
                writer.begin(getElement());
            else
                writer.beginEmpty(getElement());

            writer.attribute(getUrlAttribute(), constructURL(l, linkComponent.getAnchor(), cycle));

            beforeBodyRender(writer, cycle, linkComponent);

            // Allow the wrapped components a chance to render.
            // Along the way, they may interact with this component
            // and cause the name variable to get set.

            wrappedWriter = writer.getNestedWriter();
        }
        else
            wrappedWriter = writer;

        if (hasBody)
            linkComponent.renderBody(wrappedWriter, cycle);

        if (!disabled)
        {
            afterBodyRender(writer, cycle, linkComponent);

            linkComponent.renderAdditionalAttributes(writer, cycle);

            if (hasBody)
            {
                wrappedWriter.close();

                // Close the <element> tag

                writer.end();
            }
View Full Code Here

        cycle.setAttribute(ATTRIBUTE_NAME, this);

        _outerWriter = writer;

        IMarkupWriter nested = writer.getNestedWriter();

        renderBody(nested, cycle);

        // Start the body tag.
        writer.println();
        writer.begin(getElement());
        renderInformalParameters(writer, cycle);

        writer.println();

        // Write the page's scripting.  This is included scripts
        // and dynamic JavaScript, including initialization.

        writeScript(_outerWriter);

        // Close the nested writer, which dumps its buffered content
        // into its parent.

        nested.close();

        writer.end(); // <body>

    }
View Full Code Here

        }

        HttpServletResponse response = context.getResponse();
        PrintWriter servletWriter = response.getWriter();

        IMarkupWriter writer = new HTMLWriter(servletWriter);

        writer.print(URI);

        writer.flush();
    }
View Full Code Here

        verifyControls();
    }

    public void testNullProperty()
    {
        IMarkupWriter writer = newWriter();
        DescribableStrategy strategy = newStrategy();

        trainForTitle(writer, "Null Property");
        trainForKeyValue(writer, "null", HTMLDescriptionReceiver.NULL_VALUE, true);
View Full Code Here

    }

    public void testHTMLDescriber()
    {
        IMarkupWriter writer = newWriter();
        DescribableStrategy strategy = new NoOpStrategy();

        RootDescriptionReceiverFactory factory = newReceiverFactory();

        trainGetReciever(factory, writer, new HTMLDescriptionReceiver(writer, strategy));

        String object = "Tapestry";

        writer.print("Tapestry");
        writer.println();

        replayControls();

        HTMLDescriberImpl d = new HTMLDescriberImpl();
        d.setReceiverFactory(factory);
View Full Code Here

        return (RootDescriptionReceiverFactory) newMock(RootDescriptionReceiverFactory.class);
    }

    public void testDescribeAlternate()
    {
        IMarkupWriter writer = newWriter();
        DescribableStrategy strategy = newStrategy();

        Object alternate = new Object();

        HTMLDescriptionReceiver dr = new HTMLDescriptionReceiver(writer, strategy);
View Full Code Here

TOP

Related Classes of org.apache.tapestry.IMarkupWriter

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.