Java Web Frameworks Igor Polevoy

viraginityfumblingΛογισμικό & κατασκευή λογ/κού

2 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

64 εμφανίσεις

Java Web Frameworks

Igor Polevoy


Open Source Java Frameworks


JPublish


Jucas


MyFaces


WebOnSwing


Chrysalis


VRaptor


Swinglets


Millstone


Wicket


SwingWeb


Barracuda


ThinWire


Struts


Turbine


Tapestry


WebWork


Cocoon


Spring


Maverick


Echo


SOFIA


Verge


Anvil


Jaffa


Japple


RIFE


DWR


JSPWidget


JOSSO


JAT


OpenXava


Stripes


Click


ZK


Caramba


wingS


Helma


Restlet


Brill


Aranea Web Framework


RSF


Strecks


Google Web Toolkit


Aurora


...

Struts 2


Pros:


Simple architecture
-

easy to extend


Tag Library is easy to customize with


FreeMarker or Velocity as view technology


Use of Interceptors


Controller
-
based or page
-
based navigation


Cons:


Small Community (compared to Struts
1
)


Struts 2 Demo


Web 2.0


Web taken to on the next level


after the .com bust of
90s


Social Networking


Mashups


integration of content from multiple
sources


Lightweight business model


build it fast and they will
come, then keep on improving


New excitement about web innovation


Examples: social blogging, bookmarking, tagging,
sharing and creating collective content


Blogs, Wikies, photo sites with tagging, reviews, etc.

Web 2.0 Technology Landscape


More dynamic applications


Users participate in creation of content


Applications have more value on
-
line (some
applications would not be possible off
-
line)



Rich user interfaces (down with page refresh)



AJAX


based RUI (rich user interface)



REST/SOAP


Folksonomies

Web 2.0 Technology Landscape


Client Technologies


AJAX


Flash Macromedia


HTML/Java Script/DHTML/CSS


Java Applet


ActiveX


Early Examples


MS Outlook Web


as of
1999

REST


Representational State Transfer (REST)
-

set
of principles


XML, JSON, text, anything over HTTP


Verbs are HTTP methods: GET: READ or
COPY, PUT: UPDATE or PASTE OVER,
POST: CREATE or PASTE AFTER, DELETE:
DELETE or CUT


Nouns are entities:


http://example.com/users/


http://example.com/users/{user} (one for each user)


JSON

(JavaScript Object Notation)



Lightweight computer interchange format

{


"type": "menu",


"value": "File",


"items": [


{"value": "New", "action": "CreateNewDoc"},


{"value": "Open", "action": "OpenDoc"},


{"value": "Close", "action": "CloseDoc"}


]

}

JSON


Easy to parse on JavaScript


Every language has a JSON parser


Less verbose than XML


http://www.json.org/

Simple AJAX Demo


Google Web Toolkit


Windowing Component Toolkit (similar to AWT,
Swing, SWT, etc)


only for the web


Provides a number of widjets:


buttons, labels, tabbed panes, trees, etc.


Model:


Write RUI applications in Java


Compile the Java application into JavaScript


Generates a highly performant application (same as
hand
-

coded)



Used in many Google applications (GMail)


GWT Demo


Adobe Flex


ActionScript


MXML


Flex SDK


free, Flex Builder
-

commercial


JBoss Seam


Marriage of EJBs and JSF


http://www.jboss.com/products/seam


From Seam documentation:


Exadel Flamingo


JBoss Seam + Adobe Flex


http://code.google.com/p/exadel
-
flamingo/

Flamingo Architecture


Integration Library


Set of client side components


Supporting tools


Flamingo Validation

import org.hibernate.validator.Length;

..

@Length(min=
3
, max=
40
,
message=“
Last name too
short or too long”
)


public

String

getLastName() {


return

lastName
;

}



<flamingo:EntityValidator id="validator"


destination="{destination.text}"



validationTarget="{target.text}"


source="{test}"


property="text"


required="false"/>

name of server component

name of server component property

UI component

UI component property

Flamingo Demos


Hello World


Validation

Groovy


James Strachan is behind Groovy (first ideas in
2003
)


Version
1.0
came out on January
2
,
2007


Current version:
1.5


Java


oriented Dynamic Language


Runs on JVM


Native access to anything Java (you can write Java
code inside Groovy code)


More OO than Java (everythign is object, including
primitives)


http://www.jcp.org/en/jsr/detail?id=
241




Groovy Closures


anonymous function
-

reusable


//define:

def cl = {print "hello!"}


//call:

cl()


Closures continued

class Hi

{


void hello(Closure c)


{


for (x in 0..9)


c(x)


}

}


def h = new Hi()

h.hello{ println it}


More OO than Java


3.times {


println "hello number: ${it}"

}

Collections Define Closure methods


Range



(
0
..
9
).each{println it}


not limited to numbers:



('a'..'z').each{println it}


List:

def x = [
1
,
2
,
3
, “hello”]

x.each{println it}


Map:

def m = [firstName:”Joe”, lastName:”Shmoe”]

m.each{k, v
-
> println “${k} => ${v}”}


Spread dot operator (applied to every item in collection)

assert [
1
,
3
,
5
] == ['a', 'few', 'words']*.size()

Duck Typing


Java:


if I have
x
, I have to cast it to something to call a
method:



((Something)x).someMethod()



Groovy:


x.someMethod()

Duck Typing Example


class Duck {

void quack() { println "I am a Duck" }

}

class Frog {


void quack() { println "I am a Frog" }

}

[ new Duck(), new Frog() ].each {
it.quack()}

NOTE: no inheritance!

Welcome to Grails


Who is behind Grails? Graeme Rocher


SpringSource acquired company behind Grails

Grails…


Copy of Ruby on Rails


Runs on JVM


Uses Groovy as dominant language (Java as second in
command)


Convention over configuration


Builds a WAR file


Compiles Groovy into bytecode


Based on:


Spring


Hibernate


Quartz


Etc.


Grails

let’s‏build‏and‏app


grails create
-
app address


grails create
-
domain
-
class person


grails create
-
domain
-
class address


Grails

add properties to entities

class Person {


static hasMany = [address:Address]



String firstName


String lastName


Date dob


String toString()

{



"${firstName} ${lastName}“


}

}

class Address {


String address1


String address2


String city


String state


String zip



Person person

}

NOTE: red color marks one to many relationship

Grails

generate controllers/views

grails generate
-
all person

grails generate
-
all address

Grails

configuration


copy mysql connector to [project]/lib


Adjust
DataSource.groovy

for MySQL:


driverClassName =
"com.mysql.jdbc.Drive"


username = “grailsuser"


password = “****"


development url =
"jdbc:mysql://localhost:
3306
/test"


Grails Run/Explore

grails run
-
app

Various Dynamic Technologies


OpenLaszlo

-

Flash


Based XML GUI engine


DWR

-

JavaScript


Java communication channel


A Java Servlet running on the server that processes requests and sends
responses back to the browser.


JavaScript running in the browser that sends requests and can
dynamically update the webpage.


allows calling of server side components from JavaScript directly


provides generated serialization


demo


Dojo

-

very popular AJAX library


... and tens of other AJAX frameworks, such as:


EyeOS
-

Web OS

Conclusion


Development is moving from request/reply to
richer interfaces


Things will get very different


Development is difficult (but should not be)


Choices and possibilities are mind boggling


Need to be careful designing UI


no more
“standard”‏UI‏components


Interesting times