Search in sources :

Example 6 with Heartbeat

use of org.apache.tapestry5.services.Heartbeat in project tapestry-5 by apache.

the class HeartbeatImplTest method nested_heartbeats.

@Test
public void nested_heartbeats() {
    Runnable r1 = mockRunnable();
    Runnable r2 = mockRunnable();
    Runnable r3 = mockRunnable();
    replay();
    Heartbeat hb = new HeartbeatImpl();
    hb.begin();
    hb.defer(r1);
    hb.defer(r2);
    hb.begin();
    hb.defer(r3);
    verify();
    r3.run();
    replay();
    hb.end();
    verify();
    r1.run();
    r2.run();
    replay();
    hb.end();
    verify();
}
Also used : Heartbeat(org.apache.tapestry5.services.Heartbeat) Test(org.testng.annotations.Test)

Example 7 with Heartbeat

use of org.apache.tapestry5.services.Heartbeat in project tapestry-5 by apache.

the class Form method onAction.

@SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
Object onAction(EventContext context) throws IOException {
    beforeProcessSubmit(context);
    tracker.clear();
    formSupport = new FormSupportImpl(resources, validationId);
    environment.push(ValidationTracker.class, tracker);
    environment.push(FormSupport.class, formSupport);
    Heartbeat heartbeat = new HeartbeatImpl();
    environment.push(Heartbeat.class, heartbeat);
    heartbeat.begin();
    boolean didPushBeanValidationContext = false;
    try {
        resources.triggerContextEvent(EventConstants.PREPARE_FOR_SUBMIT, context, eventCallback);
        if (eventCallback.isAborted())
            return true;
        resources.triggerContextEvent(EventConstants.PREPARE, context, eventCallback);
        if (eventCallback.isAborted())
            return true;
        if (isFormCancelled()) {
            executeStoredActions(true);
            resources.triggerContextEvent(EventConstants.CANCELED, context, eventCallback);
            if (eventCallback.isAborted())
                return true;
        }
        environment.push(BeanValidationContext.class, new BeanValidationContextImpl(validate));
        didPushBeanValidationContext = true;
        executeStoredActions(false);
        heartbeat.end();
        formSupport.executeDeferred();
        fireValidateEvent(EventConstants.VALIDATE, context, eventCallback);
        if (eventCallback.isAborted()) {
            return true;
        }
        afterValidate();
        if (!tracker.getHasErrors()) {
            tracker.clear();
        }
        String eventType = tracker.getHasErrors() ? EventConstants.FAILURE : EventConstants.SUCCESS;
        resources.triggerContextEvent(eventType, context, eventCallback);
        if (eventCallback.isAborted()) {
            return true;
        }
        // Lastly, tell anyone whose interested that the form is completely
        // submitted.
        resources.triggerContextEvent(EventConstants.SUBMIT, context, eventCallback);
        afterSuccessOrFailure();
        if (eventCallback.isAborted()) {
            return true;
        }
        if (tracker.getHasErrors() && !request.isXHR()) {
            return STREAM_ACTIVE_PAGE_CONTENT;
        }
        return false;
    } finally {
        environment.pop(Heartbeat.class);
        environment.pop(FormSupport.class);
        environment.pop(ValidationTracker.class);
        if (didPushBeanValidationContext) {
            environment.pop(BeanValidationContext.class);
        }
    }
}
Also used : Heartbeat(org.apache.tapestry5.services.Heartbeat) FormSupportImpl(org.apache.tapestry5.corelib.internal.FormSupportImpl) HeartbeatImpl(org.apache.tapestry5.internal.services.HeartbeatImpl) BeanValidationContextImpl(org.apache.tapestry5.internal.BeanValidationContextImpl)

Example 8 with Heartbeat

use of org.apache.tapestry5.services.Heartbeat in project tapestry-5 by apache.

the class Tree method toRenderCommand.

/**
 * Renders a single node (which may be the last within its containing node).
 * This is a mix of immediate rendering, and queuing up various Blocks and Render commands
 * to do the rest. May recursively render child nodes of the active node. The label part
 * of the node is rendered inside a {@linkplain org.apache.tapestry5.services.Heartbeat heartbeat}.
 *
 * @param node
 *         to render
 * @param isLast
 *         if true, add "last" attribute to the LI element
 * @return command to render the node
 */
private RenderCommand toRenderCommand(final TreeNode node, final boolean isLast) {
    return new RenderCommand() {

        public void render(MarkupWriter writer, RenderQueue queue) {
            // Inform the component's container about what value is being rendered
            // (this may be necessary to generate the correct label for the node).
            Tree.this.node = node;
            value = node.getValue();
            boolean isLeaf = node.isLeaf();
            writer.element("li");
            if (isLast) {
                writer.attributes("class", "last");
            }
            if (isLeaf) {
                writer.getElement().attribute("class", "leaf-node");
            }
            Element e = writer.element("span", "class", "tree-icon");
            if (!isLeaf && !node.getHasChildren()) {
                e.addClassName("empty-node");
            }
            boolean hasChildren = !isLeaf && node.getHasChildren();
            boolean expanded = hasChildren && expansionModel.isExpanded(node);
            writer.attributes("data-node-id", node.getId());
            if (expanded) {
                // Inform the client side, so it doesn't try to fetch it a second time.
                e.addClassName("tree-expanded");
            }
            // span.tree-icon
            writer.end();
            // From here on in, we're pushing things onto the queue. Remember that
            // execution order is reversed from order commands are pushed.
            // li
            queue.push(RENDER_CLOSE_TAG);
            if (expanded) {
                queue.push(new RenderNodes(node.getChildren()));
            }
            queue.push(RENDER_CLOSE_TAG);
            final RenderCommand startHeartbeat = new RenderCommand() {

                @Override
                public void render(MarkupWriter writer, RenderQueue queue) {
                    heartbeat.begin();
                }
            };
            final RenderCommand endHeartbeat = new RenderCommand() {

                @Override
                public void render(MarkupWriter writer, RenderQueue queue) {
                    heartbeat.end();
                }
            };
            queue.push(endHeartbeat);
            queue.push(label);
            queue.push(startHeartbeat);
            if (isLeaf && selectionModel != null && selectionModel.isSelected(node)) {
                queue.push(MARK_SELECTED);
            }
            queue.push(RENDER_LABEL_SPAN);
        }
    };
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) Element(org.apache.tapestry5.dom.Element) RenderQueue(org.apache.tapestry5.runtime.RenderQueue)

Example 9 with Heartbeat

use of org.apache.tapestry5.services.Heartbeat in project tapestry-5 by apache.

the class TapestryModule method contributePartialMarkupRenderer.

/**
 * Contributes {@link PartialMarkupRendererFilter}s used when rendering a
 * partial Ajax response.
 * <dl>
 * <dt>DocumentLinker
 * <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}
 * <dt>ClientBehaviorSupport</dt>
 * <dd>Provides {@link ClientBehaviorSupport}</dd>
 * <dt>Heartbeat</dt>
 * <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
 * <dt>DefaultValidationDecorator</dt>
 * <dt>ValidationDecorator</dt>
 * <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
 * </dl>
 */
public void contributePartialMarkupRenderer(OrderedConfiguration<PartialMarkupRendererFilter> configuration, final ValidationDecoratorFactory validationDecoratorFactory) {
    PartialMarkupRendererFilter documentLinker = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            PartialMarkupDocumentLinker linker = new PartialMarkupDocumentLinker();
            environment.push(DocumentLinker.class, linker);
            renderer.renderMarkup(writer, reply);
            environment.pop(DocumentLinker.class);
            linker.commit(reply);
        }
    };
    PartialMarkupRendererFilter clientBehaviorSupport = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            ClientBehaviorSupportImpl support = new ClientBehaviorSupportImpl();
            environment.push(ClientBehaviorSupport.class, support);
            renderer.renderMarkup(writer, reply);
            environment.pop(ClientBehaviorSupport.class);
        }
    };
    PartialMarkupRendererFilter heartbeat = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            Heartbeat heartbeat = new HeartbeatImpl();
            heartbeat.begin();
            environment.push(Heartbeat.class, heartbeat);
            renderer.renderMarkup(writer, reply);
            environment.pop(Heartbeat.class);
            heartbeat.end();
        }
    };
    PartialMarkupRendererFilter defaultValidationDecorator = new PartialMarkupRendererFilter() {

        public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
            ValidationDecorator decorator = validationDecoratorFactory.newInstance(writer);
            environment.push(ValidationDecorator.class, decorator);
            renderer.renderMarkup(writer, reply);
            environment.pop(ValidationDecorator.class);
        }
    };
    configuration.add("DocumentLinker", documentLinker);
    configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
    configuration.add("Heartbeat", heartbeat);
    configuration.add("ValidationDecorator", defaultValidationDecorator);
}
Also used : PartialMarkupRendererFilter(org.apache.tapestry5.services.PartialMarkupRendererFilter) JSONObject(org.apache.tapestry5.json.JSONObject) Heartbeat(org.apache.tapestry5.services.Heartbeat) PartialMarkupRenderer(org.apache.tapestry5.services.PartialMarkupRenderer) MarkupWriter(org.apache.tapestry5.MarkupWriter) ValidationDecorator(org.apache.tapestry5.ValidationDecorator)

Example 10 with Heartbeat

use of org.apache.tapestry5.services.Heartbeat in project tapestry-5 by apache.

the class SubmitTest method trigger_immediate.

@Test
public void trigger_immediate() {
    FormSupport support = mockFormSupport();
    ComponentResources resources = mockComponentResources();
    Heartbeat heartbeat = new HeartbeatImpl();
    Request request = mockRequest();
    String elementName = "myname";
    train_getParameter(request, Form.SUBMITTING_ELEMENT_ID, null);
    train_getParameter(request, elementName, "login");
    replay();
    heartbeat.begin();
    Submit submit = new Submit(request);
    TestBase.set(submit, "resources", resources, "formSupport", support, "heartbeat", heartbeat, "defer", false);
    submit.processSubmission("xyz", elementName);
    verify();
    expect(resources.triggerEvent(EventConstants.SELECTED, null, null)).andReturn(false);
    replay();
    heartbeat.end();
    verify();
}
Also used : Heartbeat(org.apache.tapestry5.services.Heartbeat) Request(org.apache.tapestry5.http.services.Request) FormSupport(org.apache.tapestry5.services.FormSupport) HeartbeatImpl(org.apache.tapestry5.internal.services.HeartbeatImpl) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

Heartbeat (org.apache.tapestry5.services.Heartbeat)7 Test (org.testng.annotations.Test)4 MarkupWriter (org.apache.tapestry5.MarkupWriter)3 ValidationDecorator (org.apache.tapestry5.ValidationDecorator)2 Element (org.apache.tapestry5.dom.Element)2 HeartbeatImpl (org.apache.tapestry5.internal.services.HeartbeatImpl)2 PartialMarkupRenderer (org.apache.tapestry5.services.PartialMarkupRenderer)2 PartialMarkupRendererFilter (org.apache.tapestry5.services.PartialMarkupRendererFilter)2 ComponentResources (org.apache.tapestry5.ComponentResources)1 FormSupportImpl (org.apache.tapestry5.corelib.internal.FormSupportImpl)1 Request (org.apache.tapestry5.http.services.Request)1 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)1 ComponentWorker (org.apache.tapestry5.internal.transform.ComponentWorker)1 InjectComponentWorker (org.apache.tapestry5.internal.transform.InjectComponentWorker)1 MixinAfterWorker (org.apache.tapestry5.internal.transform.MixinAfterWorker)1 MixinWorker (org.apache.tapestry5.internal.transform.MixinWorker)1 PageActivationContextWorker (org.apache.tapestry5.internal.transform.PageActivationContextWorker)1 PropertyWorker (org.apache.tapestry5.internal.transform.PropertyWorker)1 RenderCommandWorker (org.apache.tapestry5.internal.transform.RenderCommandWorker)1 RetainWorker (org.apache.tapestry5.internal.transform.RetainWorker)1