J Rivet by EchoMovement


									                 Java Solutions for Enterprise Applications

Example 2 – Simple Data Entry Screen
C O D E   E X A M P L E S

The following examples outline creating simple screens using the jRivet framework. All
examples have been included in the preconfigured Windows Tomcat build. More complex
examples including tables, tree tables, and tabbed tables and time charts can be found in the
example applications. Examples of prompting, parameter passing, drill downs screens and
xml reports can also be found in the sample applications.

E X A M P L E   2

A Simple Data Inquiry Screen
In this tutorial we will be creating a very simple inquiry screen to display data from a
database table. The window will have record navigation buttons within the navigation
bar and data fields based on database table columns from a ‘Products’ table. Please note:
the creation of the ‘Products’ database table is beyond the scope of this document. For
this tutorial we will make the assumption that the table has been created and the JDBC
driver has access to it. Then when we are all done the window should look something
like the following:

Step one is to create the XML document that will describe the attributes of the window.
The following document will render the above window:

A little more complex then our ‘Hello World’ example but still a basic XML screen
definition. Within the button-bar tags we have 3 record navigation buttons and another to
clear the screen. The ‘Find-It’ button will execute the Java method ‘getProducts’ from
the NwProducts class. Within the body of the document we have field definitions to
display the various table columns from the table. All the field objects in the above
document are text fields. The following table lists all the field, group and container
objects currently supported by jRivet XML:

Object Name                Tag                         Object Type

Check Box                  <CheckBox/>                 Field Component

Combo Box                  < ComboBox/>                Field Component

Combo Item           < ComboItem/>          Data Element

List Box             < ListBox/>            Field Component

Image Box            <ImageBox/>            Field Component

Image Field          < ImageField/>         Field Component

Radio Button Group   <RadioButtonGroup/>    Field Container

Radio Button         < RadioButton/>        Field Component

Menu Explorer        < MenuExplorer/>       XML Container

Panel                < Panel/>              Container

Report Editor        < ReportEditor/>       XML Container

Script Editor        < ScriptEditor/>       XML Container

Menu Editor          <MenuEditor/>          XML Container

Spinner Field        < SpinnerField/>       Field Component

Tab Group            < TabGroup/>           Group Container

Tab Item             < TabItem/>            Container

Table                 < Table/>                Table Container

Tab Table             < TabTable/>             Table Container

Tree Table            <TreeTable/>             Table Container

Table Check Box       <TableCheckBox/>         Field Component

Table Spinner Field   < TableSpinnerField/>    Field Component

Table Image Field     <TableImageField/>       Field Component

Table Combo Box       <TableComboBox/>         Field Component

Table Text Field      <TableTextField/>        Field Component

Text Area             <TextArea/>              Field Component

Text Field            <TextField/>             Field Component

Search Text Field     <SearchTextField/>       Search Component

Time Chart            <TimeChart/>             Chart Container

Time Chart Data       TimeChartData            Chart Field

The following Java source snippet contains a ‘getProducts’ method.          This method is
wired to the ‘Find-it’ button in the above XML screen definition:

Let’s spend some time reviewing the above Java method. The DataSet object passed in
the method’s signature contains all data elements passed from the client. The string
‘keyField1’ is populated from the client’s DataSet object with the table key value used to
access the table. Next we create Result Set and SQL Statement objects used to access
the database. The DataAccess object passed in the method’s signature is used to get a
database connection and initialize the SQL Statement object. Next, the SQL Statement
object executes a query against the database. The returned table row is loaded into the
Result Set object.     A ‘for’ loop structure is then used to load the table row from the
Result Set into the client’s DataSet object. The complete method is encased in ‘try/catch’
structure to ensure the table is accessed without any glitches. The last step is to pass the
SQL Statement object back to DataAccess in order to close things off and clean up data
connects. The client’s DataSet object is passed back for client rendering.

Within the for loop structure we use a ‘tablefields’ object. The function of this object is
simply to get the data type for each column in the table. The field name and the data type
are both passed to DataAccess in order to read the value of each column in the returned
table row.

Similar methods need to be coded for the screens ‘nxtProducts’ and ‘prvProducts’
buttons. Once complete, compile the class and place it in the servers CLASSES folder.
Add appropriate menu tags to the menu XML document in order to access the new screen

Restarted your HTTP web server and load the jRivet application. If all went well you
should be able to select the new option and be presented with the new window.


To top