AppComposer ships with a variety of example projects. This page provides an overview of those examples and the functionality they include. All of the examples live in the AppComposer/examples subdirectory. Most of the example projects are servlets. They are designed to run on a web server and generate HTML output that can be displayed in a standard web browser.
The following table provides a breakdown of some key elements of web applications and the examples that contain them. Click on the name of any example in the table to go to its description.
Element | Example(s) |
---|---|
database | Bank, BugDatabase, Netcard, tableExample |
EJBs | Bank, icDVD, Library, MutualFund |
email from a servlet | Netcard |
embedded capsule | SubCapsuleExample |
exception handling | BugDatabase, calculator, Poll, MutualFund |
HTML select (populating) | dropListExample |
JSPs | Bank, BugDatabase, icDVD, Library, Math, MutualFund, Poll |
FreeMarker templates | SimpleFMExample, SillyHouse, FMWebAppEx2 |
return value from a method | SubCapsuleExample |
servlet ->servlet calls | jpeg |
system values, accessing | printprops |
Web Services | MFwithServices |
A few examples, found in the clientside subdirectory of the examples directory, are applications. They have their own user interface, and can be saved as either stand-alone applications or as applets.
To run these example projects from within AppComposer, you must have the AppComposer debug Web server enabled. From the Edit menu, select "Preferences..." and set the WebServerEnabled preference to true (in the DebugServer tab). The ServerPort preference sets the port on which the debug server will serve Web pages. If you already have a Web server on your machine serving pages on port 80 (the default for Web servers), then you must change this value to something else (typically port 90 on Windows).
Once the debug Web server is enabled, you can open any standard Web browser (such as Netscape Navigator or Microsoft Internet Explorer) and point it at the URL http://localhost. If you have changed the ServerPort preference, then you will have to specify the port number after the host name, separated by a colon. For example, if you have changed the port number to 8080, then set your browser to listen to http://localhost:8080. The AppComposer debug Web server displays all open servlets; you can execute the servlet by clicking on the servlet name.
In addition, many of these projects use the HSQL database. You should start the database by setting the DatabaseServerEnabled preference to true (in the General tab of the AppComposer Preferences dialog).
One easy way to run many of these examples is to open the examples/exampleProject.zap project. From there, you can open individual example capsules or projects.
These are a set of banking-related servlets that use the SimpleBank Enterprise Java Bean (EJB) that ships with AppComposer. SimpleBank is an entity bean with bean-managed persistence that talks to an HSQL database representing a customer bank account.
Note: In order to run the Bank example servlets you must import the SimpleBank bean into AppComposer, deploy the bean to the jBoss EJB server, and run the jBoss server. Instructions for those steps can be found in the Working with EJBs in AppComposer chapter of the DigiSlice AppComposer User's Guide. When running any of these examples, you can use a user account number of "111111" and a password of "whatever".
Bank/SimpleBank.zac contains the simplest servlet. This servlet prompts the user for an account number, and then uses the SimpleBank bean to retrieve the account balance. Note that step by step instructions for creating this capsule can be found in the SimpleBank Tutorial.
Bank/BankTransactions contains a project that combines EJBs and JSPs. The JSPs are accessed using the JSPTemplate bean. The first page of this project prompts the user for an account number and a password. The second page allows the user to make transactions against the account (withdraw and deposit).
Bank/BankJSPBean contains a project that re-implements the BankTransactions project, this time using a capsule of type JSPBean instead of type Servlet. To run this example, load the BankJSPBean.zap project and then open and run the login.jsp capsule.
Capsule: examples/Bank/SimpleBank.zac
Projects: examples/Bank/BankTransactions/BankTransactions.zap, examples/Bank/BankJSPBean/BankJSPBean.zap
bugdb is a reasonably large database-enabled example servlet. You can search for bugs, add new bug reports, and edit existing bug reports. To run it, open the servlet Find.zac.
Note: The HSQL database server must be activated within AppComposer before running the capsule for this example.
Project: examples/BugDB/BugDatabase.zap
This six function calculator works like an adding machine with a tape. Makes extensive use of multiple stimuli on action events, and exception handling.
Capsule: examples/calculator.zac
Demonstrates how to display an HTML select element, initialized with a series of options retrieved from a database. Populating a select element from a database is a very common servlet task.
Note: The HSQL database server must be activated within AppComposer before running the capsule for this example.
Capsule: examples/droplistExample.zac
This set of three servlets implements a guest log, so visitors to a web site can "sign" the log and leave comments.
Project: examples/FreeMarkerExamples/webappexample2/FMWebAppEx2.zap
Makes extensive use of EJBs and JSPs to implement a commercial e-commerce site (online DVD rental) using AppComposer. To run this example:
This set of three servlets demonstrates the use of the JpegSaver bean. This bean lets you create an image dynamically on the server, and download it as a JPEG image to a browser. Also shows how to call one servlet from another.
The ballPage.zac servlet calls the ballImage.zac servlet to draw increasingly zoomed in views of a simple image. The clockimage.zac servlet draws an analog clock showing the current time. The samplePage.zac servlet draws an image and encodes it using various levels of quality, showing the tradeoff between image quality and image size.
Project: examples/Jpeg/jpeg.zap
Uses: asset/ball.gif
The Library examples are a set of library-related projects that use the BookEnterpriseBean EJB that ships with AppComposer. BookEnterpriseBean is an entity bean with bean-managed persistence that talks to an HSQL database representing a library system.
Note: In order to run the Library examples you must import the BookEnterpriseBean into AppComposer, deploy the bean to the jBoss EJB server, and run the jBoss server.
Library/Library/Library.zap uses the BookEnterpriseBean and JSPs to allow a library patron to check books in and out of the system, and add new books to the system. Library.zac uses a JSPTemplate bean to display the file library.jsp, which displays the status of the books in the library and allows the user to interact with the system. LibraryResponse.zac and AddBookResponse.zac display JSP pages containing system responses to user requests.
Library/LibraryAddJSPCapsule/LibraryAddJSPCapsule.zap uses capsules of type JSPBean to re-implement the Add Book portion of the primary Library example. To run this example, load the LibraryAddJSPCapsule project into Application Composer and then open http://localhost/LibraryAddJSPCapsule/html/LibraryAdd.html in your web browser.
Projects: examples/Library/Library/Library.zap,
examples/Library/LibraryAddJSPBean/LibraryAddJSPCapsule.zap
The Math project illustrates simple interaction between JSP and HTML pages and a capsule. It also demonstrates numeric processing of servlet parameters, using scripts, and creating looping behaviors.
Project: examples/Math/Math.zap
mortgage is a servlet-based mortgage payment calculator.
Capsule: examples/mortgage.zac
MutualFund is a web site for Reliance Mutual Funds, a fictitious investment company. This example is a complete version of the application you build in the Mutual Fund Tutorial.
To run the Mutual Fund demo:
Project: examples/MutualFund/MutualFund.zap
This example re-implements the Mutual Fund site using web services.
To run the Mutual Fund demo:
You must be connected to the Internet in order to run this demo, since the Mutual Fund service resides on a remote server (ws-demo.digislice.com).
Project: examples/MFwithServices/MutualFund.zap
Netcard is an application for sending and receiving greeting cards over the Web. The project netcard.zap contains three servlets: netcard.zac, pickup.zac, and request.zac. Includes an example of how to send email from a servlet.
Note: The HSQL database server must be activated within AppComposer before running the capsule for this example.
To run this example, first open the request.zac servlet and double-click on the "mailmessage" bean to edit its properties. Fill in the "Mailhost" property with the name of the SMTP server you use for sending email. Then close the request.zac servlet, open the netcard.zac servlet, and execute it.
The netcard.zac servlet displays 6 greetings cards that can be sent via email. The request.zac servlet processes the greeting card chosen from netcard.zac and sends the card once the sender and receiver have been entered. The recipient of the greeting card receives an email message with a URL for the pickup servlet, which displays the appropriate card (selected by the parameters given as part of the URL).
Project: examples/Netcard/netcard.zap
Poll is a set of servlets for taking user polls. The servlet PollHome is the starting point for the project. It displays a main page from which you can create new polls or find existing polls. PollEdit creates new poll topics and edits existing polls. PollFind retrieves existing polls from the database, and PollDelete deletes existing polls from the database. PollDisplay uses an HTML document to display the poll itself. And PollResults displays the current voting results of a poll.
Note: The HSQL database server must be activated within AppComposer before running the capsules for this example.
Project: examples/Poll/poll.zap
Displays the value of all the Java System properties. Shows all the system values available to a servlet, and also is an example of a simple servlet.
Capsule: examples/printprops.zac
This capsule uses the FreeMarkerBean to implement a silly game where people wander around a house until they get hungry and stop in the kitchen to make a sandwich. It also shows a way of storing and managing session data.
Project: examples/FreeMarkerExamples/simpleexamples/FMExamples.zap
This capsule uses the FreeMarkerBean and the Clock bean to display the current time.
Project: examples/FreeMarkerExamples/simpleexamples/FMExamples.zap
This capsule demonstrates the practice of using one capsule as a component in another capsule. It also shows how an embedded capsule can return a complex data type, in this case a Vector of Strings. The capsule FindByCity.zac defines a method called getCompanies, which returns a Vector containing the names of all companies located within a particular city. SubCapsuleExample.zac includes FindByCity.zac, and calls its getCompanies method to build a table of companies located in the city selected by the user.
Note: The HSQL database server must be activated within Application Composer, and the project examples\ExampleProject.zac must be open, for this example to run correctly.
Capsules: examples/FindByCity.zac, examples/SubCapsuleExample.zac
Dumps a database table and displays it as an HTML table. Note: The HSQL database server must be activated within AppComposer before running the capsule for this example.
Capsule: examples/tableExample.zac
Each application example consists of one file in the examples subdirectory of the AppComposer installation directory, and optionally several files in the asset subdirectory. All of the examples are capsules that can be opened directly from within AppComposer.
Displays a blue box that turns a different shade of blue when clicked. Demonstrates use of a simple behavior. Note that in the toybox view, closing and reopening the toybox reinitializes the box. The toybox only stores edited changes, not changes based on behavior execution.
Capsule: examples/clientSide/BlueBoxClick.zac
Beans: com.digislice.spin.display.Rect.
Assets: none.
Displays two objects, a box and a ball, contained within an opaque scene. Each have the same complex behavior -- bounce -- that drops the object and makes it bounce when clicked with the mouse.
Capsule: examples/clientSide/Bounce.zac
Beans: com.digislice.spin.display.Rect, com.digislice.spin.display.ImageURL.
Assets: asset/ball.gif.
Combines analog, digital, and cuckoo clock, all in one! For demonstration purposes, you can click on the clock to make it cuckoo. To make it act like a normal cuckoo clock, change the cuckoo behavior (under the chime actor) to activate on Time.hour.timeChanged rather than background.Mouse.mouseClicked. Note that an analog clock is an example of something that would be difficult to build in an authoring tool like Director.
Capsule: examples/clientSide/Clock.zac
Beans: com.digislice.spin.misc.DateTime, com.digislice.spin.misc.AudioURL, com.digislice.spin.display.Rect, com.digislice.spin.display.Drawable, com.digislice.spin.display.Text
Assets: asset/snd/cuckoo.au
Displays a single rectangle which can be dragged around with the mouse. The drag behavior is a complex behavior created within Composer. Drag is also available as a prebuilt user behavior.
Capsule: examples/clientSide/Drag.zac
Beans: com.digislice.spin.display.Rect.
Assets: none.
This simple drawing application allows you to draw multiple lines to make an image. Also allows you to change the color of the image.
Capsule: examples/clientSide/Scribble.zac
Beans: com.digislice.spin.display.Drawable, com.digislice.spin.display.Rect.
Assets: none.
Displays current stock graph images fetched from the yahoo site. Enter a ticker symbol, and hit Display, or simply choose a symbol from the list.
Capsule: examples/clientSide/StockGraph.zac
Beans: com.digislice.spin.display.ImageURL.
Assets: none.
Displays stock graph images fetched from a limited set on disk. Essentially this is the same as StockGraph above, except it does not require an Internet connection. Symbols are limited to those for which there are assets (see list below), and of course the stock data is not current.
Capsule: examples/clientSide/StockGraphLocal.zac
Beans: com.digislice.spin.display.ImageURL.
Assets: chart/a/aapl.gif, adbe.gif, adsk.gif,
chart/c/cisc.gif, cpq.gif,
chart/d/dell.gif,
chart/i/ibm.gif
chart/m/macr.gif, msft.gif
chart/n/nscp.gif
chart/s/sunw.gif
chart/t/tek.gif, txn.gif
The XML examples are currently unsupported, and are provided "as is". They can be found in AppComposer/examples/clientSide/XML.
Each of the XML examples uses an XML file in the same directory as the XML example capsules called Book.xml (%install%/examples/xml/Book.xml). The XML content of this file is shown below:
<Book Author="Mocha Joe">
<Title>Composer Rules</Title>
<Chapter id="1">Components</Chapter>
<Chapter id="2">Servlets</Chapter>
<Chapter id="3">Databases</Chapter>
<Chapter id="4">EJB</Chapter>
<Chapter id="5">Fun Stuff</Chapter>
</Book>
The SAXEcho example show you how to use a SAX1Parser Component and listen for events from that Parser. A TextArea is used to show the output of the actions that listen for events from the SAX1Parser.
The only unusual action is the setUrl Action. Since the location of Book.xml will change with each installation, the setUrl action will figure out at runtime where the file is located and set the Url of the Parser to the exact location.
The actions in this capsule listen for standard events that are generated by an XML parser, such as startDocument, startElement, and characters.
Capsule: examples/clientside/xml/SAXEcho.zac
XMLApp uses a SAX1Reader and SAX1ElementPatterns to parse an XML file. SAX1Reader inherits from SAX1Parser, but has some added functionaility. SAX1Reader can use SAX1Patterns (SAX1ElementPattern and SAX1InstructionPattern) to look for matching elements in an XML document. You can achieve the same with a SAX1Parser through actions, but the SAX1Patterns make the task a little easier. All events that are available through SAX1Parser are also available in a SAX1Reader component.
SAX1ElementPatterns and SAX1Instructions patterns must be child nodes of a SAX1Reader to recevice event notifications.
If you look at the node named BookElement, it has it's "Name" field set to "Book". This means that every time a Book element is found in the XML, this node will get notification of the event. In the XML file used (Book.xml), the Book element is the root of the document and has an attribute called Author. The setAuthor action under BookElement gets the value of the Author attribute and saves it for display later. The TitleElement is similar.
The ChapterElement gets a notificaiton when a Chapter tag is being processed. Every time a Chapter tag is encountered, the data enclosed in the Chapter tags is added to the "Chapters" list for display.
Capsule: examples/clientSide/xml/xmlapp.zac
XmlToHtml reads an XML file and converts the contents to HTML using specific instructions based on knowledge of the structure of the XML document. It's structure is similar to XmlApp, but the actions format the tags in HTML rather than outputing the element to a list or window.
Capsule: examples/clientSide/xml/xmltohtml.zac