- Apache Tapestry 教程
- Apache Tapestry - 主页
- Apache Tapestry - 概述
- Apache Tapestry - 架构
- Apache Tapestry - 安装
- Apache Tapestry - 快速入门
- Apache Tapestry - 项目布局
- 约定优于配置
- Apache Tapestry - 注释
- 页面和组件
- Apache Tapestry - 模板
- Apache Tapestry - 组件
- 内置组件
- 表单和验证组件
- Apache Tapestry - Ajax 组件
- Apache Tapestry - Hibernate
- Apache Tapestry - 存储
- 高级功能
- Apache Tapestry 有用资源
- Apache Tapestry - 快速指南
- Apache Tapestry - 有用的资源
- Apache Tapestry - 讨论
Apache Tapestry - Ajax 组件
AJAX 代表异步 JavaScript 和 XML。它是一种借助XML、JSON、HTML、CSS和JavaScript创建更好、更快和更具交互性的 Web 应用程序的技术。AJAX 允许您异步发送和接收数据,而无需重新加载网页,因此速度很快。
区域组件
区域组件用于提供内容(标记)以及内容本身的位置。Tapestry 在内部使用区域组件的主体来生成内容。生成动态内容后,Tapestry 会将其发送到客户端,在正确的位置重新呈现数据,触发 HTML 并为其设置动画以吸引用户的注意。
该区域组件与 EventLink 组件一起使用。EventLink 可以选择使用t:zone属性将其绑定到特定区域。在 EventLink 中配置区域后,单击 EventLink 将触发区域更新。另外,EventLink事件(refreshZone)可以用来控制动态数据的生成。
AJAX 的一个简单示例如下 -
AjaxZone.tml
<html t:type = "Newlayout" title = "About MyFirstApplication"
xmlns:t = "http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p = "tapestry:parameter">
<body>
<h1>Ajax time zone example</h1>
<div class = "div1">
<a t:type = "eventlink" t:event = "refreshZone" href = "#"
t:zone = "timeZone">Ajax Link </a><br/><br/>
<t:zone t:id = "timeZone" id = "timeZone">Time zone: ${serverTime}</t:zone>
</div>
</body>
</html>
AjaxZone.java
package com.example.MyFirstApplication.pages;
import java.util.Date;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;
public class AjaxZone {
@Inject
private Request request;
@InjectComponent
private Zone timeZone;
void onRefreshPage() {
}
Object onRefreshZone() {
return request.isXHR() ? timeZone.getBody() : null;
}
public Date getServerTime() {
return new Date();
}
}
结果将显示在:http://localhost:8080/MyFirstApplication/AjaxZone
