WorkStation Setup

 

 

 

 Workstation Setup

Workstation Setup


Connection Pool Setup

 

Downloads

FrameWork Jars

 

Sample Default Properties Files

 

Standard Html folder structure

 

 

 

 

 

What is a framework? A framework is a design pattern (or patterns) used in to increase development productivity. A framework is not a development environment, but is instead a development structure which will reduce redundancy and complexity - while adding value, and maintaining flexibility.

The definition above is mine, it is by no means the 'official' definition of the term, but is instead the product of my experience. Take it or leave it...

What is an AsyncFW? Traditional web applications accept data from the user and perform a ‘Submit’. The server receives the posted data, processes it, and returns an html page to the user.  With an Asynchronous framework, you control what data is sent to the server and waiting for a response is optional. 

Sound a bit like Ajax? Well it is. The AsyncFW embraces Ajax fully (as well as Comet, for server ‘push’ to client communications) . AsyncFW also includes FWDirect  (similar to DWR) to allow client side access to POJO classes (Plain Old Java Objects), as well as Service support (SOA).

Embracing the new, does not mean we have tossed out the tried and true – at its core the AsyncFW is a Servlet based architecture, using XSLT – all under the covers, yet still accessible if need be.

Referring to the above diagram, lets walkthrough what the AsyncFW brings to the table. The framework wraps the HTTPServlet request and performs the following prior to handing off to the business logic;

  1. First the user is validated, and session state information is managed.
  2. Next, the type of request if determined, AsynceFW supports 4 Major request types;
    1. User form interaction – standard webpage data collection and submission
    2. SOA request – Service request, usually machine to machine
    3. Direct class access – Calling server based Java class methods from JavaScript
    4. Comet (not shown in diagram) – Asynchronous server side updates pushed to the client (Reverse Ajax).
  3. Once the request type is know the framework hands off to the appropriate handler.
  4. Request data is marshaled into an FWDoc object (a custom AsyncFW structure)
  5. An FWDoc Response object is created and pre-populates it with the request data. 
  6. User is optionally validated.
    1. If the user is valid, or is a returning 'all ready validated' user. The state object is create or restored.
  7. The requested forms meta-data is loaded from the database and loaded into the FWDoc Response object.
  8. The execute method of your servlet (known as a ServiceLet in F4J) is called.

 

Once a request is received, and passed to your class for processing, the developer does not need to worry about user validation, Database connection access, or state restoration. The AsyncFW framework has already done that. He/She simply needs to implement the business logic around the request and load or update values in the FWDoc response object. Once the execute method completes, the following occurs;

 

  1. The FWDoc response object is converted to XML
  2. The XML is transformed via XSLT
  3. The response is written to the client

 

The developer does not need to concern themselves with any of the transformations, state maintenance, or the marshalling of data to and from request and response objects – this is what the framework deals with. When a new AsyncFW servlet is constructed, it is fully functional without a single line of code. By default the request is marshaled into the response, and if no action is taken, the response is parroted back – unchanged.  To implement your business logic, you will need to implement the ‘Execute(FWSession)’ method of the FWServiceLetInt interface.

Let’s look at some code!

 

public class customer extends FWHttpServiceLet implements FWServiceLetInt {

       

        private static final long serialVersionUID = 1L;

        private static String XSLT_customer = "/html/xsl/customer.xsl";

       

        // *The below line should be uncommented for forms caching

    //private static FWResultSet MyResult = new FWResultSet();

   

        public customer(){

               super();

        }

.
.
.

 

The code above represents the Servlet ‘customer’. All AsyncFW servlet classes must implement the FWServiceLetInt interface.  The extended FWHttpServiceLet is a super class, this class is extended for all web and service based classes with one exception, Comet. For a Comet Servlet, you will need to extend the FWCometServiceLet.  Both extend the HTTPServlet class.

The Execute() method

 

Once you have create your AsyncFW servlet, you will need to implement the .Execute(FWSession fwSess) method. As stated earlier, this is where you get to do your work. The default processing is to simply parrot back the request with whatever data the user has entered. Below is a sample of an execute method for the “customer” servlet.  The code shown is all that is needed to perform basic CRUD (create, read, update delete)  against a MySQL database table of the same name (‘customer’).

 

 

public void Execute(FWSession fwSess) throws FWException {

    SqlDOManager sql = null;

    try {

        sql = new SqlDOManager(fwSess, (String) DBProps.getAppDatabases().get(0));

        DoCustomer uiObj = new DoCustomer(fwSess);

        if (uiObj.getsysAction().equalsIgnoreCase("customerAddButton")) {

               sql.insert(uiObj);

        }else if (uiObj.getsysAction().equalsIgnoreCase("customerUpdateButton")) {

               sql.update(uiObj);

        }else if (uiObj.getsysAction().equalsIgnoreCase("customerDeleteButton")) {

               sql.delete(uiObj);

        }else if (uiObj.getsysAction().equalsIgnoreCase("customerFindButton")) {

               sql.select(uiObj);

               sql.next();

        }else {

           //Default Handler - just display the form input

           fwSess.getSessionResp().getField("sysErrors").AddChild("Msg",

"Welcome to the CUSTOMER entry/edit form.");

        }

        }catch(Exception err){

               fwSess.getSessionResp().getField("sysErrors").AddChild("Msg", err.getMessage());

        }finally{

               if(null != sql)

                       try{sql.close();}catch(Exception e){}

        }

}

I expect the code above will seem a bit foreign at this point, and that is fine for now, but there are couple of things worth pointing out. First the Execute method takes a single parameter; an FWSession object. The FWSession object is created and inflated by the FWHTTPServiceLet super class.  The super class has performed all necessary user validation, and session state management for you, so you only need to think about the business logic.  Also, note the DoCustomer object. This object represents the request and response object specific to this form (customer in this case).

So what does that mean? Well, if the user entered “Bob” in the customer “First Name” field on the form, and submits that form to the server, you can access it by simply doing a uiObj.get_FirstName(); If you want to change the first name, and send the change back to the browser, you would simple perform a uiObj.set_FirstName(“Sally”); - nothing more.

The above code is an example of what the FWAdmin tool will generate for you. The code above is complete, and functional. There is nothing more required to Add, Update, Delete, or Find records in the ‘customer’ database table and the results are returned to the user.

There is much more to cover, but for now just note that besides your workstation setup, and application configuration, there is nothing more to code, than what you see above, to accomplish the basic client/server interactions. In addition to the lightweight start-up code, you will also have Getter and Setter access to the response object, database objects, etc. This alone will make development and maintenance much easier.

One last point of interest, before we move on…

While we will dive into the Data Access model in much more detail, you may be wondering about the sql.select statement – What is it selecting? By default, it will construct a select statement based on the supplied object. If the user had entered a “First Name” and a “Zip Code”, for example, the .select() method would look for any non-null values in the object, and construct the appropriate select statement.

Next Step: Workstation setup: WorkStation Setup

 

 

Copyright 2009. All rights reserved by

S. Chappell