分享
 
 
 

Web DbForms

王朝java/jsp·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Web DBForms

作者:Joachim Peer

(说明:由于本人水平有限,所以翻译错误在所难免。为了不给读者造成错误的概念,这里采用了中英文对照方式)

Joachim Peer is an independent J2EE developer. He holds a masters degree in Management Information Systems of Johannes Kepler University, Linz, Austria, with a focus in the fields of software engineering, multimedia application development and knowledge and process management. He is a Sun certified programmer for the Java 2 platform.

Joachim Peer是个独立的J2EE开发者。他有奥地利林茨的约翰尼斯开普勒大学的MIS硕士学位,主攻software engineering, multimedia application development and knowledge and process management。他还是个Sun认证的基于Java 2 平台的程序员。

Many developers find themselves writing similar JSP and servlet code again and again when creating Web-based database applications. The open source project DbForms provides a solution that reduces the amount of coding to an absolute minimum.

许多开发者发现,当创建基于Web的数据库应用程序时,会一遍又一遍地重复写相似的JSP和Servlet代码。开放源代码的项目DbForms提供了将代码的数量降至最低的解决方案。

This article gives an overview of DbForms and its concepts and features, and shows some code examples.

本文简单介绍了DbForms和它的概念与特点,并给出了一些示例代码。

Introduction

介绍

DbForms is a Java-based Rapid Application Development (RAD) environment which enables developers to build Web-based database applications in a very short time and with very little effort. DbForms applications are built in a conceptually very similar manner to RAD database-building tools like Microsoft Access (for Windows-based applications) or Sybase PowerSite (for Web-based applications). The basic principle of these RAD-Tools could be described as "placing database-aware components and action elements on templates (forms) which get executed at runtime."

DbForms是一个基于Java的快速应用程序开发环境,使开发者在最短的时间里,用最少的工作量创建基于Web的数据库应用程序。DbForms应用程序在概念上与微软的Access(基于Windows的应用程序)或者Sybase PowerSite(基于Web的应用程序)等的开发工具有非常相似的风格。这些快速开发工具的基本原理是“把database-aware组件和action elements放在模板中,在运行期执行”。

DbForms builds on top of Java Servlets 2.2 and Java Server Pages 1.1 technologies by Sun Microsystems. It makes extensive use of the JSP Tag Library extension introduced in the JSP 1.1 specification.

DbForms是建立在Sun Microsystems公司的Java Servlets 2.2和JSP1.1技术上。它大量的使用了JSP标签库,可参见JSP1.1文档。

The project's homepage is located at http://www.dbforms.org and contains a complete user manual, several technical articles, source and binary distributions, online examples, a CVS, mailing lists, and lots of other information related to DbForms.

此项目的主页是 http://www.dbforms.org ,包含了一个完整的用户手册,许多技术文章,源代码和二进制的分发包,在线示例,一个CVS,邮件列表和DbForms的许多其他相关信息。

The MVC Paradigm Incorporated by DbForms

MVC范例,由DbForms组合

DbForms implements the concepts of the Model-View-Controller (MVC) design pattern. (See Design Patterns: Elements of Reusable Object-Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, Addison Wesley, October 1994.) You do not need to provide any Controller-related code; just focus on defining the Model and creating the JSP view components of the application (mainly using DbForms custom tags).

DbForms实现了模型-视图-控制器设计模式的精神。(参见《设计模式:可复用面向对象软件的基础》Erich Gamma, Richard Helm, Ralph Johnson和John Vlissides著,Addison Wesley公司出版,1994年10月) 你不用写控制器相关的代码,可以把精力放在应用程序的模型定义和JSP视图组件建立(主要是用DbForms标签)上。

The following discusses how Model, View and Controller interact in DbForms.

下面讨论模板,表示和控制器在DbForms中是如何交互的。

The Model: Database Objects Described by Database Metadata

模型:用数据元描述的数据库对象

The use of DbForms is to perform operations on databases. The database tables accessed by a DbForms application must be declared in a XML configuration file (usually stored as WEB-INF/dbforms-config.xml), which is parsed and evaluated at Web-application startup time.

DbForms的使用是为了完成对数据库的操作。DbForms应用可以访问的数据表要在一个XML配置文件(通常保存为WEB-INF/dbforms-config.xml)中描述。

Listing 1. Defining the model

1 定义模型

<dbforms-config xmlns="http://www.wap-force.net/dbforms">

<table name="customer">

<field name="id" fieldType="int" isKey="true" />

<field name="firstname" fieldType="char" />

<field name="lastname" fieldType="char" />

<field name="address" fieldType="char" />

</table>

<table name="orders">

<field name="orderid" fieldType="int" isKey="true" />

<field name="customerid" fieldType="int" isKey="true" autoInc="true" />

<field name="date" fieldType="char" />

<field name="annotation" fieldType="char" />

<field name="amount" fieldType="int" />

</table>

<dbconnection

name = "jdbc/dbformstest"

isJndi = "true"

/>

</dbforms-config>

As shown in Listing 1, every table (or view) to be accessed by DbForms has to be declared inside of a <table> element. All relevant table fields need to be declared inside of a <field> element nested within its respective <table> element.

从Listing 1中可以看出,DbForms可以访问的每个数据表(或视图)必须要在<table>元素间声明。所有相关的表字段也要在<table>元素间嵌套<field>元素来声明。

There exists a tool for generating this XML data automatically. The tool reads database metadata of a specified database and constructs a configuration file, as shown in Listing 1.

有一个可以自动产生这个XML数据的工具。该工具读取特定的数据库的数据元,建立一个配置文件,如Listing 1中所示。

The Controller: Parsing, Dispatching, and Executing Events

控制器:解析,分派,执行Events

As pointed out above, you do not need to provide any Controller-related code when the Controller is a true infrastructural component. However, it's useful if you have an idea of what's going on inside the Controller. The following lines provide that information.

如上所述,当控制器是个基础组件时,你不需要写任何控制器相关的代码。然而,了解了控制器内部的运行机制也很有用。

The Controller includes several components:

控制器包含的组件:

ControllerServlet: this servlet is the single point of entry for all incoming HTTP requests from clients.

ControllerServlet: 该servlet是所有从客户端来的HTTP请求的入口点。

EventEngine: an assistant to the ControllerServlet, it focuses on filtering HTTP requests for WebEvents and instantiates them.

EventEngine: ControllerServlet助理,主要是为WebEvents过滤HTTP请求,并例示之。

WebEvent Objects: all Objects derived from the abstract super-class WebEvent have the ability to initialize themselves by reading a given HTTP request. These events get executed, either directly by the Controller or by the View.

WebEvent对象:所有由抽象超类WebEvent派生的对象,他们能读取一个给定的HTTP请求来初始化自己。这些events直接被控制器或视图执行。

The following description of the execution of a typical user action should give you a better picture of what the controller does and how it interacts with the other components:

下面的一个典型用户动作执行的描述,更好的描绘了控制器做什么和怎样与其他组件互相作用:

1.User presses the button "delete row" on his/her DbForms application.

用户点击DbForms应用程序的“delete row”按钮。

2.Client browser submits data via HTTP-POST to the Controller-servlet.

客户端浏览器通过HTTP-POST提交数据给Controller-servlet。

3.The ControllerServlet delegates the incoming request to the EventEngine, which determines the main event (the user explicitly triggered the event by clicking a button). However, there may occur implicit events, too -- i.e., automatic updating of all changed input fields of all data rows.

ControllerServlet把请求委派给EventEngine,由它来决定主event(用户通过点击按钮显式触发event)。然而,也会有隐含events发生—例如,自动更新所有数据rows的已变的输入字段。

4.The EventEngine component parses that request and determines the kind of action the user wants to be executed.

EventEngine组件解析请求,并决定用户要执行的动作种类。

5.It then creates the appropriate WebEvent (in our case, a DeleteEvent) and delegates the request Object to this newly-created WebEvent, which finalizes its own initialization. After that, the EventEngine returns the recently-created and -initialized event back to the ControllerServlet.

然后,建立适当的WebEvent(在我们的案例中,是一个DeleteEvent),并将请求对象委派给这个新建的WebEvent,来完成自己的初始化。这之后,EventEngine把刚产生的和初始化了的event返回给ControllerServlet。

6.The ControllerServlet tells the event to execute its built-in operation, if it is a DatabaseEvent. Other events (NavigationEvent, etc.) are delegated to the appropriate View component.

如果是个DatabaseEvent,ControllerSErvlet会让这个event来执行其内部操作。其他的events(NavigationEvent等等)会被委派给合适的视图组件。

7.The ControllerServlet invokes EventEngine again to check if there are additional (implicit) events to be executed. If so, the appropriated WebEvent Objects are created and executed in the same manner as the main event described above.

ControllerServlet再次调用EventEngine来检查是否有另外(隐含)的events被执行了。如果有,在和上面提到的主event一样方式的适当的WebEvent对象会被建立和执行。

8.The ControllerServlet determines the View component to which the request should be forwarded. If found, the ControllerServlet invokes the component and forwards the request.

ControllerServlet指定请求要传送给哪个视图组件。如果找到了(此组件),该ControllerServlet会调用该组件,然后传送请求。

9.If the View component is a JSP page containing DbForms tags, those tags will search for navigation events to be executed, and will finally generate the response for the user.

如果视图组件是一个包含DbForms标签的JSP页面,并且这些标签会查找要执行的navigation events,那么最终会为用户产生相应。

10.The response is rendered by the user's Web browser.

这个相应会被用户的Web浏览器表示出来。

The View: JSP Templates Provided by the Application Developer

视图:应用程序开发者提供的JSP模板

The View portion of a DbForms application is generally constructed using JSP technology. JSP files may contain static HTML elements, as well as dynamic elements containing Java code (definitions, statements, expressions). For more information about JSP, please see Sun's JSP page.

DbForms应用程序的视图部分通常使用JSP技术来构建。JSP文件会包含HTML元素,也包含动态Java代码(定义,声明,表达式)。想更多的了解JSP,请浏览Sun公司的JSP主页。

With release 1.1 of the JSP API, a powerful facility called JSP tag libraries was added. With these custom tags, you can encapsulate even most sophisticated Java code into lightweight JSP tags.

随着JSP API 1.1的诞生,增加了一个强大的工具叫做JSP标签库。利用这些标签,你可以把大部分复杂的Java代码封装到轻便的JSP标签里。

DbForms makes use of the great potential of JSP tag libraries. It contains an extensive custom tags library for rendering and manipulating database data.

DbForms利用了JSP标签库的巨大潜能。它包含一个扩展的用户自定义标签库来显示和操作数据库数据。

The Structure of a DbForms View

一个DbForms视图的结构

Figure 1 gives a conceptual overview of the main components of a typical DbForms view.

图1给出了一个典型DbForms视图的主要组件的初步概述。

The Basic Concepts of Forms

Forms的基本概念

Each DbForms-view JSP may have one or more root tags of the type form. Every form tag has to contain exactly one header tag, exactly one body tag, and exactly one footer tag, in exactly that order.

每个Dbforms视图JSP都可能有一个或多个类型表单根标签。每个表单标签必须正确的包含一个header标签,一个body标签,和一个footer标签,并且有正确的顺序。

Each of those tags may contain sub-elements like data fields, input fields, action buttons, and -- of course -- plain HTML text and JSP code.

每个标签可能包含子元素,例如数据域,输入域,动作按钮,当然了,还有纯HTML文本和JSP代码。

header and footer tags are commonly used for titles of pages, labelling tables, placing action and navigation buttons, input fields to enter new data, etc. header and footer tags get evaluated only once.

header和footer标签通常是用于页面的标题,标注表,安置动作和导航按钮,输入域用于输入新数据,等等。header和footer标签只用一次。

The body tag is used for showing data rows coming from the database, and for providing the user with the functionality to edit that data. How many times the body tag and its sub-elements get rendered depends on the value of the maxRows attribute of the form element (and of course, on the number of datasets actually fetched from the database).

body标签是用于显示数据库中的数据行,并提供给用户编辑数据的功能。body标签和其子元素要显示多少次取决于表体元素(当然了,这要看实际从数据库中取出的数据集的数量)maxRows属性值。

maxRows = n -- body gets executed n times at maximum (with n in N)

maxRows = n -- body最大执行n次(n<N)

maxRows = "*" -- body gets executed for every row in the table ("endless" form)

maxRows = "*" -- body执行表每行(“无穷”表体)

Nested Forms

嵌套Forms

Every form may contain one or more nested sub-forms inside its body element.

每个表单的表体里面包含一个或多个嵌套的子表单。

The "orders" form is nested within the body element of the "customer" form, as shown in Figure 2. The user will see one customer per page (because maxRows is set to "1") and all the orders (because maxRows = "*") the customer has taken. The user may navigate through the list of customers by clicking the navigation buttons.

“订单”表单嵌套在“客户”表单的体元素内,入图2所示。每页用户会看到一个客户(因为maxRows设置为“1”)和客户所有的订单(因为maxRows设置为“*”)。用户在客户列表中通过点击导航按钮来查看。

OK, Let's See Some Code!

好了,让我们看些示例代码!

As stated before, JSP views are the only parts of a DbForms application a developer usually needs to put his/her hands on. DbForms provides an extensive custom tag library which makes this an easy task, so that it can be performed even by non-programmers.

如上所述,JSP视图是开发者要处理的DbForms应用程序中的唯一部分。DbForms具有一个扩展用户自定义标签库,用它可以轻松(处理JSP视图),因此,即使是非程序员也可以做到。

As we will see later, much of this code can be generated automatically by tools included in DbForms. However, it is useful to understand the basics of DbForms views, even if much of the work can be done automatically.

后面我们会看到,很多代码都可以用DbForms内部的工具来自动产生。然而,很有必要了解DbForms视图的基本要素,即便是很多工作都可以自动被完成。

The following two sections will show a simple and a more advanced example of a DbForms view. Both examples can be thought as being parts of a little CRM application of a (virtual) agency.

下面两部分会展示DbForms视图的一个简单和一个复杂的例子。这些例子都可以被看作是一个(假想的)销售商的部分简单的客户资源管理应用程序。

(未完待续)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有