首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

在 Apache Wink 中使用 Dojo Grid 和 Dojo Tree 小部件(1)

在 Apache Wink 中使用 Dojo Grid 和 Dojo Tree 小部件(1)

简介REST 是一种用于分布式超媒体系统(比如 World Wide Web)的软件架构。资源,或者特定信息来源是 REST 的一个重要组成,每个资源都可以通过一个全局标识符引用。例如,在 HTTP 中 URI 是一个标识符。要对资源进行操作,网络组件(用户代理和源服务器)之间使用一个标准化接口通信,比如 HTTP,并交换资源的表示(传递信息的实际文件)。
Wink 是一个可用于 REST 开发的框架。Wink 为 REST web 服务的开发和使用提供便利,根据 REST 架构风格为服务建模提供方法。Wink 也为定义和实现资源、表示以及构成一个服务的统一方法提供了必要的基础架构。它干净地将低级协议和应用程序分离开来。要实现和使用 REST web 服务,您只需要关注应用程序业务逻辑,而不需要关注低级技术细节。但是,Wink 目前还不支持 Dojo 小部件,比如 Dojo Grid 和 Dojo Tree。
在本文中,了解如何编写新的服务提供方程序以及如何将它们插入 Wink。探究使用含基于 Dojo 的 GUI 的 Wink 的优势。您可以 下载 本文所使用的样例 Dojo 服务提供方程序。
网格 网格(或数据格栏)在客户端/服务器开发模式中是很常见的。网格 本质上是一种电子表格,通常用于显示主从结构( master-detail)表单上的详情。在 HTML 中,一个网格是一个 “超级表”,拥有自己的可滚动视图端口。一个结构 是一系列视图,而一个视图 则是一系列单元格。清单 1 展示了 Dojo 网格的一个样例格式。  
清单 1. 网格格式
1
2
3
4
5
6
7
8
9
10
11
{
items: [
{"id":0, "name": "Alex", "manager": "T", "sex": "M", "age":30},
{"id":1, "name": "Jack", "manager": "F", "sex": "M", "age":26},
{"id":2, "name": "Rose", "manager": "F", "sex": "M", "age":31},
{"id":3, name: "Wang","manager": "T", "sex": "M", "age":36 },
..],
"endRecordIndex"=0,
"totalRecords"=0,
"startRecordIndex"=0
}




要实现一个表示,您应该创建一个 REST 资源。清单 2 中的示例创建了一个 Java™ 类 DojoList。
清单 2. Dojo 网格资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
public class DojoList<T>{
protected ArrayList<T>items;
private int endRecordIndex ;
private int totalRecords ;
private int startRecordIndex ;

@XmlElement(name = "items")
public ArrayList<T> getItems() {
if (items == null) {
items = new ArrayList<T>();
}
return items;
}

public void setItems(ArrayList<T> newList) {

items = newList;

}


@XmlElement(name = "endRecordIndex")
public void setEndRecordIndex(int endRecordIndex) {
this.endRecordIndex = endRecordIndex;
}


public int getEndRecordIndex() {
return endRecordIndex;
}

@XmlElement(name = "totalRecords")
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}

public int getTotalRecords() {
return totalRecords;
}


@XmlElement(name = "startRecordIndex")
public void setStartRecordIndex(int startRecordIndex) {
this.startRecordIndex = startRecordIndex;
}


public int getStartRecordIndex() {
return startRecordIndex;
}

}




是一个定义了 “父子” 关系的层次结构。例如,就一个管理者和一个员工之间的实体关系来说,多个员工是被一个管理者管理的。他们之间的关系也可以认为是一种 “父子” 关系。这类 “父子” 关系可以在一个 Dojo 树中显示出来。Dojo 树的一个样例网格格式如清单 3 所示。
清单 3. 网格树格式
1
2
3
4
5
6
7
8
9
{
items: [
{"id":0, "name": "Alex", manager: "T", "sex" : "M", "age" : 30, "children" : {"child":[
{"id":1,"name":"Jack",sex: "M", "age" : 26},
{"id":2, "name" : "Rose", "sex" : "F", "age" : 26},
{"id":3,"name":"Phil",sex: "M", "age" : 27}
]},....
…..],
}




要实现这个表示,您要创建一个 REST 资源。清单 4 中的示例创建了一个 Java 类 DojoTree。
清单 4. Dojo 树资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
@XmlType(propOrder = {"items"})
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlRootElement(name = "dojoItems")

public class DojoTree<T> {

protected ArrayList<T> items;

@XmlElement(name = "items")
public ArrayList<T> getItems() {
if (items == null) {
items = new ArrayList<T>();
}
return items;
}

public void setItems(ArrayList<T> newList) {

items = newList;


返回列表