JSP examples

Do not run this file locally
Run it from your (local) web server where is installed your http and JSP server like Apache Tomcat and the J2SE runtime environment (JRE).

The JSP service program must have write access to all files database.* and also must have write access to the directory /Examples/Jsp/
To permit write access on Windows XP right click to folder Jsp in My Computer, select Properties -> Security -> Users and set Full control to Allow. If you don't have Security item in Properties, run My Computer, in menu select Tools - > Folder options -> View and uncheck Use simple file sharing option.

You have to copy files hsqldb.jar and TreeGrid.jar to your JRE shared lib directory and restart your http server
These files are located in TreeGrid distribution in /Server/JSP/ directory.
The shared lib directory is usually jre_install_path/lib/ext and also for example in Tomcat is usually tomcat_install_path/shared/lib.
hsqldb.jar file is JDBC driver for HSQLDB database that is used in nearly all examples.
TreeGrid.jar is support code for using TreeGrid server side library, this library is used in example Ajax grids with using server DLL/SO.

TreeGrid JSP Framework

When writing JSP script you can use TreeGrid JSP framework functions to help generating and parsing XML files and reading it from and updating changes to database.
The framework is located in single file TreeGridFramework.jsp and can be included into your JSP pages by standard include mechanism <%@include file="TreeGridFramework.jsp"%>.
See TreeGrid JSP framework documentation.
Nearly all examples use this framework, so look at them to learn how to use the framework.


JAVA server pages


Ajax

Asynchronous background (new style) communication with server.
Data are downloaded from or uploaded to server by JavaScript XmlHttpRequest object on background, without reloading/submitting the page content.
You can check from configuration menu option Auto update changes to server for immediate updates after edit/modify.
When debugging, you can set <treegrid ... Debug='3' ... > to see communication with server. It opens two new browser's windows. You can see XML data or JSP error server returned.
Remember, in Ajax communication, the jsp page must return only xml data, not any standard html tags like <html> or <!doctype>.
See documentation AJAX versus submit and also tutorial Identifying rows when uploading.

Ajax table
Main file AjaxTable.html, support code AjaxTable.jsp
Layout file in TableDef.xml, data in database table "TableData".
The simplest demonstration of using JSP and AJAX. It generates data from database table 1:1 including id. Also updates changes to database according/with id.
This is only independent file without using TreeGrid JSP framework.

Ajax table with framework
Main file AjaxTableFramework.html, support code AjaxTableFramework.jsp, framework code TreeGridFramework.jsp
Layout file in TableDef.xml, data in database table "TableData".
The same example as previous Ajax table but with using functions from TreeGrid JSP Framework. Also shows using user parameters.

Ajax table with server side paging and export
Main file AjaxTablePaging.html, support codes AjaxTablePaging.jsp , AjaxTablePagingPage.jsp , AjaxTablePagingExport.jsp
Layout file in TableDef.xml, data in database table "TableData".
The same example as previous Ajax table but with using server paging and export routine.
The pages are downloaded on demand from server (when the page is visible by scrollbars).
It is simple example with ineffective database access - it loads all table for every page and throws the rest away.
It also simply reloads all body when rows are added or deleted instead of handling changes in pages.

Ajax tree with framework
Main file AjaxTreeFramework.html, support code AjaxTreeFramework.jsp, framework code TreeGridFramework.jsp
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid JSP Framework.

Ajax Extended API with reloading
Main file AjaxAPI.html, support codes AjaxTableFramework.jsp and AjaxTreeFramework.jsp , framework code TreeGridFramework.jsp
Layout files in TableDef.xml and TreeDef.xml, data in database tables "TableData" and "TreeData".
It shows two tables from previous examples and demonstrates Extended API functions for reloading, changing data source when reloading, catching data event and so on.

Ajax grid
Main file AjaxGrid.html, support codes AjaxGridData.jsp , AjaxGridLayout.jsp , AjaxGridUpload.jsp
Data in database table "TableData".
Demonstrates advanced generating from and updating to database.
Generates treetable from standard database table. Also flips the table and shows data in changed layout.
For every action is used another support code (Layout, Data, Upload). The layout is also generated.
Rows are identified by one unique editable column, with using full ids (including parents ids).
For demonstration it shows id column, to see what ids are generated by TreeGrid.

Complete application - Schools
Main file Schools.html
Support codes Schools.jsp (main file generates data and also saves changes to database or adds new user),
SchoolsRatings.jsp (loads reviews for given record, used for server child paging),
SchoolsReview.jsp (saves one review to database, called as custom AJAX call).
Layout file in SchoolsDef.xml, data in database tables "Schools_Schools", "Schools_Ratings" and "Schools_Users".
Uses also file SchoolsStars.gif ()
Complete application to demonstrate generating from and updating to different database tables with various structure. Demonstrates also server child paging feature (loading children on demand). And also custom AJAX call.
The application show list of schools that can be sorted and filtered. The records can be added/deleted or modified by logged user or admin. The records can be rated and reviewed by visitors.



Ajax and DLL

This JSP example uses TreeGrid server library
To run it, you need to copy file TreeGrid.jar to your shared lib directory.

Ajax DLL upon XML file and checking for updates
Main file AjaxServerDLLDisk.html, support code AjaxServerDLLDisk.jsp
Layout file in Data2Def.xml, data file in Data2.xml.
Demonstrates using server DLL upon static XML data file.
Also demonstrates sharing data among more clients and automatic updating client's data after data on server are modified by another client.
The JSP service program must have write access to file /Examples/ServerDLL/Data2.xml !


Main examples - paging

To save changes the JSP service program must have write access to /Examples/ServerDLL/tmp directory !

The main file ../ServerDLL/ServerDLL.html can be executed with various parameters:

Ajax server paging with DLL
Main file ../ServerDLL/ServerDLL.html?src=../Jsp/AjaxServerDLL.jsp with JavaScript support code ../ServerDLL/ServerDLL.js.
JSP support code AjaxServerDLL.jsp uses ../../Server/TreeGrid.dll component (TreeGrid server library).
Uses file DataXZDef.xml as layout and DataXY.xml as data source. Where X is example index and Y is rows index (0='S', 1='', 2='E'), Z can be 'E' for server paging.
Remember, XML data files DataXE.xml for 50000 rows are not included in this distribution due their size and can be downloaded from www.treegrid.com/Download/DataE.zip.



Submit

Synchronous (old style) communication with server.
Data are included in page in hidden input. Changes are sent to server in the hidden input of submitted <form> on page.
See documentation AJAX versus submit and also tutorial Identifying rows when uploading.

Submit table
Main file SubmitTable.jsp
Layout file in TableDef.xml, data in database table "TableData".
The simplest demonstration of using JSP and standard page submit. It generates data from database table 1:1 including id. Also updates changes to database according/with id.
The code is nearly the same as in Ajax table.

Submit table with framework
Main file SubmitTableFramework.jsp, framework code TreeGridFramework.jsp
Layout file in TableDef.xml, data in database table "TableData".
The same example as previous Submit table but with using functions from TreeGrid JSP Framework.

Submit tree with framework
Main file SubmitTreeFramework.jsp, framework code TreeGridFramework.jsp
Layout file in TreeDef.xml, data in database table "TreeData".
Generates treetable from database table with column Parent where are relations Parents/Children. Parent column contains parent's id of the child. For root rows it contains "#Body", for fixed rows "#Head" or "#Foot".
Uploaded rows are still identified by preset and standardly generated id attributes.
Uses functions from TreeGrid JSP Framework.
The code is nearly the same as in Ajax tree.