Package com.tapestry5book.pages.chapter11

Source Code of com.tapestry5book.pages.chapter11.MultiZoneCallbackDemo

package com.tapestry5book.pages.chapter11;

import org.apache.tapestry5.Asset;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.annotations.Path;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ajax.AjaxResponseRenderer;
import org.apache.tapestry5.services.ajax.JavaScriptCallback;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;

import java.util.Date;

public class MultiZoneCallbackDemo {

    @Property
    @Persist
    private int number;

    @Inject
    private Block numberBlock;

    @Inject
    private AjaxResponseRenderer ajaxResponseRenderer;

    @Inject
    @Path("initializers.js")
    private Asset initializers;

    void onIncrement() {
        this.number++;

        ajaxResponseRenderer
                .addRender("numberZone", numberBlock);

        ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
            public void run(JavaScriptSupport support) {

                support.importJavaScriptLibrary(initializers);

                JSONObject parameters = new JSONObject("id", "status",
                        "newContent", "Updated on " + new Date());

                support.addInitializerCall(
                        "replaceContent", parameters);
            }
        });

    }
}
TOP

Related Classes of com.tapestry5book.pages.chapter11.MultiZoneCallbackDemo

TOP
Copyright © 2018 www.massapi.com. 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.