25
Front-ends Application programs today use a number of different techniques for their front-ends, the part of the application that is responsible for user interaction. Both stand-alone GUI applications and GUI modules are used. You may use classes that upon instantiation provides an application with its user interface, stand-alone applications that implement the interface, documents that configure a web browser (html, xhtml, php, jsp, asp, javascript or generic GUI) DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 1 / 25

Modern database systems & their applications

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Modern database systems & their applications

Front-ends

Application programs today use a number of different techniques for theirfront-ends, the part of the application that is responsible for user interaction.

Both stand-alone GUI applications and GUI modules are used.

You may use

• classes that upon instantiation provides an application with its user interface,

• stand-alone applications that implement the interface,

• documents that configure a web browser (html, xhtml, php, jsp, asp,javascript or generic GUI)

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 1 / 25

Page 2: Modern database systems & their applications

Front-ends . . .Demands on application programs increase. Often it is not enough to develop forone platform as users tend to migrate between systems and there is anevergrowing Linux/Unix community.

view

html wml jfc/swing xml

controllermodel

Middle−tier

Back−end

Front−end

jsp/jsf

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 2 / 25

Page 3: Modern database systems & their applications

Front-ends . . .To keep the discussion down I will mainly talk about JSP/JSF(html,wml,xml), JSP/Strutsand JFC/Swing. It is possible to let JSP/JSF generate XML that may be used in conjunctionwith XSL to be transformed to XML for web services, WML for smartphones/handheldcomputers and (X)HTML for web browsers.

In the dominant model for building applicatiions, MVC, it is not all that simple do make thedistinction between view and controller.

It might be simpler to follow the PAC* model that manages all interaction in the presentationmodule.

But then again, most frameworks conform to MVC and it might not be easy to break thatpattern.

JSP enables the developer to use Java in HTML pages. It matters if you use Java toimplement the rest of your application. One language for everything (almost).

JSP also enables you to use user defined tags which, in turn makes it possible to use thirdparty tag “tool boxes” or tag libraries.

One of many is JSF. When I start my Eclipse or Netbeans I have support for JSTL(JavaServer Pages Standard Taglib) and Struts and Spring + some others.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 3 / 25

Page 4: Modern database systems & their applications

JSP/JSF - Java Server Pages/Java Server Faces

With JSF you get a complete infrastructure, a bit like Struts. It was the opinion ofmany that JSF would be the successor to Struts while others meant they wouldcomplement each other. Noone can say today which or even if any of them willsurvive.

Right now it seems that JSF has become a complement to all other techniquesand many use Struts + JSF, Spring + JSF, EJB + JSF, . . .

In reality they are comparable but the JSF toolbox and widgets are moresofisticated.

In other words there are more possibilities to tweak things in JSF. But there is acost in terms of a rather complicated life cycle. . .

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 4 / 25

Page 5: Modern database systems & their applications

JSP/JSF . . .

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 5 / 25

Page 6: Modern database systems & their applications

JSP/JSF . . .

A request passes 6 stages before generating the response.

The “Reconstitute Request Tree” phase creates a component tree for the requested page(generates a representation for the view).If the page has already been shown and if JSF has saved the page state this info will beautomatically added (stolen I guess from MS WebForms).So, no extra cost for keeping the page info in the case of erroneous input.

During the “Apply Request Values” phase JSF iterates over all components in the tree andadds info if there is any to add.

Then every component in the tree may generate “request” events, normally to change itsown appearance or maybe that of another component.Each such request is added to the JSF environment ot be handled “in due time” which is, itturns out, when entering the next event process phase.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 6 / 25

Page 7: Modern database systems & their applications

JSP/JSF . . .

At the end of the third phase there is one call to the processEvents method for eachcomponent having one or more pending event requests.

A component may handle the event itself or delegate it to another component, which mostlymeans a special event handler.

If all goes well the result is sent to the “Render Response” phase and if not to to the“Process Validations” phase.

It is possible to attach validation requirements to the components and these requirementsare checked in the “Process Validations” phase.

Validation requests can be input verification such as the correct pattern, characters, ssnchecksum, . . .

When all checks hold or an error occurs JSF enters the “Render Response” phase.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 7 / 25

Page 8: Modern database systems & their applications

JSP/JSF . . .

It is possible to associate every component with a variable in a Java object in the applicationmodel (model part of the MVC). During the “Update Model” phase the component value iscopied to the variable and if something goes wrong (as convertions – request parametersare strings and may need to be converted) then the “Render Response” starts immediately.

Whatever takes place in the GUI is handled by JSF components that send stimuli to thecontroller to be sent on to the application model during the “Invoke Application” phase.

In the end of the JSF cycle everything is collected into a response tree that during the“Render Response” phase is sent to whatever is rendering the view, most commonly butnot necessarily a web browser.

If a user does something that generates new stimuli to any JSF view component it all startsagain.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 8 / 25

Page 9: Modern database systems & their applications

JSP/JSF . . .<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:loadBundle basename="demo.bundle.Messages" var="Message"/>

<html>

<head> <title>Input Name Page</title> </head>

<body bgcolor="white">

<f:view>

<h1><h:outputText value="#{Message.inputname_header}"/></h1>

<h:messages style="color: red"/>

<h:form id="helloForm">

<h:outputText value="#{Message.prompt}"/>

<h:inputText id="userName" value="#{nameBean.userName}"

required="true">

<f:validateLength minimum="2" maximum="20"/>

</h:inputText>

<h:commandButton id="submit" action="greeting"

value="Say Hello" />

</h:form>

</f:view>

</body>

</html>

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 9 / 25

Page 10: Modern database systems & their applications

JSP/StrutsAs Struts use a PAC*-like MVC, its life cycle gets simpler. All stimuli is sent to the controllerwhich may decide to update the model, which in turn may tell the controller that the viewneeds updating . . .

Best illustrated with a diagram:

request

Model

Controller

servlet

Controller

View

usesBeans

struts config

XML

forward

forward

dispatchuses

response

updatesresponse

Client

(web browser)

Business logic

Action Classes

JSP

Many more on the web, google for “struts framework”

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 10 / 25

Page 11: Modern database systems & their applications

JSP/Struts . . .

Values propagate via property files. Whoever is to deliver a value writes into its property fileand whoever is to fetch a value reads it from a property file. meddelande hamtar.

Struts is simpler and has a less complicated life cycle than JSF. Faster but also more static,less scalable.

Last version of Struts contains a new module, shale, increasing scalability.The price is bigger overhead and a steeper learning curve.

Struts is still simple to learn but does not scale enough to be useful in really bigapplications (big meaning Openoffice/MS office size).

JSF, on the other hand, scales well but is not good for small applications.

Struts with Shale scales better, is good for medium sized applications, OK, for big ones buta little cumbersome in small apps.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 11 / 25

Page 12: Modern database systems & their applications

JSP/Struts . . .

<%@ taglib uri="/WEB-INF/struts-html" prefix="html" %>

<html:html>

<head><title>KickStart: Input name</title></head>

<body>

<html:form action="/greeting.do">

<table border="0" cellspacing="0" cellpadding="0">

<tr>

<td><b>Input name:</b></td>

</tr>

<tr>

<td>

<html:text property="name" />

<html:submit value=" Say Hello! " />

</td>

</tr>

</table>

</html:form>

</body>

</html:html>

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 12 / 25

Page 13: Modern database systems & their applications

JFC/Swing - Java Foundation Classes & Swing

JFC/Swing is not simple to manage. There is a large number of toolboxes, mainlyin the form of GUI-builders.

Very few, though, aim at distributed applications.One of those that do is XTT (http://www.insitechinc.com/xtt.php3).Entirely built on JFC+ Swing + XML (for the communication)

With XTT you get a standalone Swing GUI.

“For free” you also get front-end – middle-tier communication in the form of XML.

In the Middle-tier there is a tiny XTT server module managing communication.(images “stolen” from www.insitechinc.com)

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 13 / 25

Page 14: Modern database systems & their applications

JFC/Swing - XTT . . .

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 14 / 25

Page 15: Modern database systems & their applications

JFC/Swing - XTT . . .

which internally uses a MVC pattern.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 15 / 25

Page 16: Modern database systems & their applications

JFC/Swing - XTT . . .

You program “as usual” – standard JFC with Swing but get “for nothing” that communicationmay be performed using HTTP. An application is easy to start by a web browser if it is JavaWeb Start aware.If not, it is simple to obtain.

All JDKs since 1.4.2 have Java Web Start. In Sun (Oracle) Java use$JAVA_HOME/bin/javaws and in openjdk JAVA_HOME/jre/bin/javaws to start the smallbut necessary server. When the browser asks what to do with files ending in .jnlp, youchoose to always use javaws. Test e.g.http://www.insitechinc.com/STOCKTRADER/demo/stocktrader.jnlp

It is good to keep the javaws server window open in order to kill dead but hangingprocesses. Not all applications that are written for Java Web Start tidy up when sessionends.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 16 / 25

Page 17: Modern database systems & their applications

JFC/Swing - XTT . . .There are free development packages for Eclipse and NetBeans.How does XTT fit into the Java hierarchy?Another set of images from the InTech site

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 17 / 25

Page 18: Modern database systems & their applications

JFC/Swing - XTT . . .

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 18 / 25

Page 19: Modern database systems & their applications

JFC/Swing - XTT . . .

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 19 / 25

Page 20: Modern database systems & their applications

What ought to reside in the front-end?

My opinion: only what the user is supposed to see and interact with

• + whatever manages the communication “downwards”

• + input validation so erroneous input is never sent to the middle-tier

• + encryption (most important password and user id but preferably all thecommunication.

Everything else is sent to the middle-tier for processing.I try to avoid comlex JavaScript on HTML pages (not so easy if you use Ajax).

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 20 / 25

Page 21: Modern database systems & their applications

More solutions

XTT is an attractive solution but there are many more possibilities if we createstand-alone front-ends. So far my discussion has been limited to Java.

One technique to communicate front-end←→ middle-tier (←→ back-end ) thatenables us to use many different languages is CORBA.CORBA (Common Object Request Broker Architecture) from OMG (the ObjectManagement Group) is an architecture for transparent network communication. Itenables application programs to use remote objects as if they were local.In essence ot is a simple idea. The client connects to an ORB (Object RequestBroker) that locates the object regardless of whether it is on the same computer orelsewhere as long as it is accessible on some ORB in the network.

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 21 / 25

Page 22: Modern database systems & their applications

CORBA . . .Anyone that wants to provide a service connects the service to an ORB as doesanyone who wants to use a service

D I I IDLstub adapter

ORB objectinterface

skeletonIDL

Object Request Broker

clientimplobject

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 22 / 25

Page 23: Modern database systems & their applications

CORBA . . .There is a large number of services but note that someone has to provide theservice. The CORBA consortium does not. They provide the infrastructure.

Object Request Brokers

Application Domain

interface services

Common

Object

services

interface

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 23 / 25

Page 24: Modern database systems & their applications

CORBA . . .

The drawback is that perts of the application must be written in a specific way thatdiffer from language to language and is managed by a preprocessor that one maydownload for each language. It enables you to communicate between applicationswritten in different languages and why not a set of applications that togetherconstitutes a distributed application with more than one front-end and more thanone back-end . . .

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 24 / 25

Page 25: Modern database systems & their applications

More on communication

CORBA communicates using the IIOP protocol (Internet Inter-Orb Protocol). A lotof work has been performed on it to make it reliable and fast. Actually faster thanother protocols and SUN (Oracle) ues it in RMI. RMI is a choise too but only if youuse Java.In the MS hemisphere you should use DCOM (ActiveX) and RPC (RemoteProcedure Call).It has a concetually somewhat simpler architechture but works approximately asCORBA with a kind of proxy for each remote object.

Finally – don’t underestimate the HTTP protocol. It is fully useable even as aninter-application information “bus”

DD2471 (Lecture 11) Modern database systems & their applications Spring 2012 25 / 25