skills matter itbo april2010 tapestry
DESCRIPTION
The Apache Tapestry web framework has been making a name for itself in terms of innovative features and ease of use.TRANSCRIPT
© 2010 Howard M. Lewis Ship
In The Brain OfHoward M. Lewis Ship:
TWD Consulting, [email protected]
1
Tapestry 5: Java Power, Scripting Ease
© 2010 Howard M. Lewis Ship
Howard Lewis Ship
• Creator, Apache Tapestry
• Author, "Tapestry in Action"
• Independent Consultant
• Java Champion
2
© 2010 Howard M. Lewis Ship
What is Tapestry?
3
© 2010 Howard M. Lewis Ship
Java4
© 2010 Howard M. Lewis Ship
Open Source
5
© 2010 Howard M. Lewis Ship
Component Based
6
© 2010 Howard M. Lewis Ship
Developer Focused
7
© 2010 Howard M. Lewis Ship
Convention over
Configuration8
© 2010 Howard M. Lewis Ship
Concise9
© 2010 Howard M. Lewis Ship
Fast!10
© 2010 Howard M. Lewis Ship
Mature11
© 2010 Howard M. Lewis Ship
Tapestry Elements
12
© 2010 Howard M. Lewis Ship
Tapestry Templates
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> <body> <h1>Please Login</h1>
<t:form> <t:label for="userId"/> <t:textfield value="userId"/> <br/> <t:label for="password"/> <t:passwordfield value="password"/> <br/> <input type="submit" value="Login"/> </t:form></html>
Login.tml
Login
form
label
textfield
label
passwordfield
13
© 2010 Howard M. Lewis Ship
Page Classes
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> <body> <h1>Please Login</h1>
<t:form> <t:label for="userId"/> <t:textfield value="userId"/> <br/> <t:label for="password"/> <t:passwordfield value="password"/> <br/> <input type="submit" value="Login"/> </t:form></html>
Login.tml
public class Login{ @Property private String userId;
@Property private String password;
Object onSuccess() { … }}
Login.java
14
© 2010 Howard M. Lewis Ship
Page Flows
public class Login{ @Property private String userId;
@Property private String password;
void onValidate() { … }
Object onSuccess() { …
return UserProfile.class; }}
Login.java
public class UserProfile{ … }
UserProfile.java
15
© 2010 Howard M. Lewis Ship
Inversion of Control
public class Login{ @Property private String userId;
@Property private String password;
…
@Inject private Session session;
@CommitAfter Object onSuccess() { …
User user = (User) session. …
user.setLastLogin(new Date());
return UserProfile.class; }}
Login.java
Inject IoC Service into field
Yourcode
Tapestry Services
16
© 2010 Howard M. Lewis Ship
Meta-Programming
public class Login{ @Property private String userId;
@Property private String password;
@InjectPage private UserProfile userProfilePage; …
@Inject private Session session;
@CommitAfter Object onSuccess() { …
User user = (User) session. …
user.setLastLogin(new Date());
return userProfilePage; }}
Login.java
Generate getter & setter
Commit Hibernate transaction
17
© 2010 Howard M. Lewis Ship
State Management
public class UserProfile{ @Property @SessionState private UserEntity user;
@Property @Persist private Date searchStart;
}
UserProfile.java
Shared global value (any page)
This page only
18
© 2010 Howard M. Lewis Ship
Component
Template
Java Class
Message Catalog
Meta-Programming
Injections
19
© 2010 Howard M. Lewis Ship
❝Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves.❞
Alan Kay, co-designer of the Smalltalk programming language
20
© 2010 Howard M. Lewis Ship
Developer Productivity
21
© 2010 Howard M. Lewis Ship22
© 2010 Howard M. Lewis Ship23
Live Class Reloading
© 2010 Howard M. Lewis Ship24
© 2010 Howard M. Lewis Ship
Non-Tapestry Exception Reporting
25
© 2010 Howard M. Lewis Ship
Index does not contain a property named 'now'
Available properties: class, componentResources, currentTime
26
© 2010 Howard M. Lewis Ship27
© 2010 Howard M. Lewis Ship
Scaffolding
28
@Entitypublic class BoardGame{ @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @NonVisual private long id;
@Validate("required") private String title;
private String creator;
private String publisher;
private Date published;
private boolean inPrint;
@Validate("required") @Column(nullable = false) private Genre genre;
@Validate("required") @Column(nullable = false) private Theme theme;
@Validate("min=1") private Integer minPlayers;
@Validate("min=1") private Integer maxPlayers;
@Validate("min=1,max=5") private Integer rating;
@DataType("longtext") private String notes;
© 2010 Howard M. Lewis Ship
BoardGame.java
29
© 2010 Howard M. Lewis Ship30
© 2010 Howard M. Lewis Ship
Property Types
Naming Conventions
Annotations
Explicit Overrides
Localized Messages
Bea
nEd
itFo
rm
Parameters
31
© 2010 Howard M. Lewis Ship32
© 2010 Howard M. Lewis Ship
Feedback &Exploration
33
© 2010 Howard M. Lewis Ship
Flow
34
© 2010 Howard M. Lewis Ship
❝PHP and Rails have taught us that development speed is more important than we thought it was ... you really don’t understand a feature till you’ve built it, so the faster you can build them the faster you understand them.❞
Tim Bray, Director of Web Technologies, Sun Microsystems
35
© 2010 Howard M. Lewis Ship
Internationalization
36
© 2010 Howard M. Lewis Ship37
© 2010 Howard M. Lewis Ship
page-title=Erstellen Sie eine neue Brettspieladd-game=Spiel hinzufŸgengame-added=Added Brettspiel
modern=Modernenmedieval=Mittelalterbible=Bibelabstract=Zusammenfassung
war_game=Kriegsspielcard=Karterole_playing=Rollenspielecooperative=Genossenschaft
creator-label=Schšpferpublisher-label=Verlagpublished-label=Veršffentlichtinprint-label=Im Drucktheme-label=Themaminplayers-label=Mindest-Spielermaxplayers-label=Maximale Spielernotes-label=Notation
Index_de.properties
<html t:type="layout" title="message:page-title" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<strong>${message}</strong>
<t:beaneditform submitlabel="message:add-game" object="game" />
</html>
Index.tml
38
© 2010 Howard M. Lewis Ship
Tapestry Components
39
© 2010 Howard M. Lewis Ship
Nested Components
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <head> <title>${title}</title> </head> <body> … <div id="menu"> <ul> <li t:type="loop" source="pageNames" value="pageName" class="prop:classForPageName"> <t:pagelink page="prop:pageName">${pageName}</t:pagelink> </li> </ul> </div>
…
Layout.tml
Layout
title : StringpageNames : List
pageName : String
Index
Layout
Loop PageLink
40
Render property pageName
© 2010 Howard M. Lewis Ship
Layout Components
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <head> <title>${title}</title> </head> <body>
. . .
<t:body/>
. . .
</body></html>
Layout.tml
<html t:type="layout" title="message:page-title" xmlns:t="http://tapestry.apache.org/schema/ ↵ tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<t:beaneditform submitlabel="message:add-game" object="game" />
</html>
Index.tml
❶
❷
❸
❹
❺
41
© 2010 Howard M. Lewis Ship
Component Parameters
public class Layout{ /** The page title, for the <title> element and the <h1> element. */ @Property @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL) private String title;
@Property @Parameter(defaultPrefix = BindingConstants.LITERAL) private String sidebarTitle;
@Property @Parameter(defaultPrefix = BindingConstants.LITERAL) private Block sidebar;
@Property private String pageName;
Layout.java
42
© 2010 Howard M. Lewis Ship
Non-Template Components
public class OutputDate{ private final DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
@Parameter(required = true, allowNull = false) private Date date;
void beginRender(MarkupWriter writer) { writer.write(formatter.format(date)); }}
OutputDate.java
43
© 2010 Howard M. Lewis Ship
Component Rendering
Start
SetupRender
BeginRender
Render Template
Render Body
AfterRender
CleanupRender
End
true
falsetrue
true
false
false
false
true
void beginRender(MarkupWriter writer) { writer.write(formatter.format(date)); }
OutputDate.java
44
© 2010 Howard M. Lewis Ship45
© 2010 Howard M. Lewis Ship46
© 2010 Howard M. Lewis Ship47
<t:actionlink t:id="selectGame" context="game" zone="gameDetail"> ${game.title}</t:actionlink>
Games.tml
@Property private BoardGame game, selectedGame;
@InjectComponent private Zone gameDetail;
Object onActionFromSelectGame(BoardGame game) { selectedGame = game;
return gameDetail.getBody(); }
Partial Page Updates
<t:zone id="gameDetail" t:id="gameDetail"> <t:if test="selectedGame"> <strong>${selectedGame.title}</strong> by <strong>${selectedGame.creator}</strong> <br /> For ${selectedGame.minPlayers} - ↵${selectedGame.maxPlayers} players. </t:if></t:zone>
Games.tml
Games.java
.../games.selectGame/3
© 2010 Howard M. Lewis Ship
Encapsulation
48
© 2010 Howard M. Lewis Ship
TapestryPerformance
49
© 2010 Howard M. Lewis Ship
Request Processing Speed
50
© 2010 Howard M. Lewis Ship
Java == Fast
51
© 2010 Howard M. Lewis Ship
No Reflection
52
© 2010 Howard M. Lewis Ship
Page Pooling
53
© 2010 Howard M. Lewis Ship
GZIP Compression
54
© 2010 Howard M. Lewis Ship
Scalability55
© 2010 Howard M. Lewis Ship
JavaScript Aggregation
56
© 2010 Howard M. Lewis Ship
Far Future Expires Header
57
© 2010 Howard M. Lewis Ship
Caching58
© 2010 Howard M. Lewis Ship
Content Delivery Network
59
© 2010 Howard M. Lewis Ship
❝Architecture is the decisions that you wish you could get right early in a project.❞
Martin Fowler, Chief Scientist, ThoughtWorks
60
© 2010 Howard M. Lewis Ship
Conclusion
61
© 2010 Howard M. Lewis Ship62
© 2010 Howard M. Lewis Ship
Infrastructure
63
© 2010 Howard M. Lewis Ship
Performance
64
© 2010 Howard M. Lewis Ship
Tapestry: The Expert is Built In
65
© 2010 Howard M. Lewis Ship
Tapestry 5 In Production
66
© 2010 Howard M. Lewis Ship
http://tapestry.apache.org
67
•Downloads•Mailing Lists•Component Reference•User's Guide•Wiki
© 2010 Howard M. Lewis Ship68
http://jumpstart.doublenegative.com.au/
•Application Skeleton•Detailed tutorials
© 2010 Howard M. Lewis Ship69
http://chenillekit.codehaus.org/
© 2010 Howard M. Lewis Ship70
http://wookicentral.com/
•Collaborative Book Authoring•Useful blog•Spinning off libraries
© 2010 Howard M. Lewis Ship71
http://tynamo.org/
•Domain-Driven Design•Improved Hibernate support•RESTful web services•JPA support
© 2010 Howard M. Lewis Ship
http://github.com/hlship/t5intro
72
© 2010 Howard M. Lewis Ship
http://howardlewisship.com
Tapestry 5 Development and SupportOn-site / Hands-on Tapestry Training
73
© 2010 Howard M. Lewis Ship
Image Credits© 2006 Chris Waltonhttp://www.flickr.com/photos/philocrites/245011706/
© 2009 Nataline Funghttp://www.flickr.com/photos/metaphora/3384569933/
© 2006 Martino Sabiahttp://www.flickr.com/photos/ezu/297634534/
© 2008 Alan Grinberghttp://www.flickr.com/photos/agrinberg/2465119180/
© 2008 Manu Gómezhttp://www.flickr.com/photos/manugomi/2884678938/
© 2006 Tom Maglieryhttp://www.flickr.com/photos/mag3737/267638148/
© 2003 A. Lipsonhttp://www.andrewlipson.com/escher/relativity.html
© 2009 viernesthttp://www.flickr.com/photos/viernest/3380560365/
© 2007 Jojo Cencehttp://www.flickr.com/photos/jojocence/1372693375/
© 2007 Patrick Dirdenhttp://www.flickr.com/photos/sp8254/2052236004/
© 2009 Dani Ihtathohttp://www.flickr.com/photos/ihtatho/627226315/
74
© 2010 Howard M. Lewis Ship
Image Credits© 2008 Christophe Delaerehttp://www.flickr.com/photos/delaere/2514143242/
© 2007 Marina Campos Vinhalhttp://www.flickr.com/photos/marinacvinhal/379111290/
© 2006 kris247http://www.flickr.com/photos/kris247/86924080/
75
© Randal Munroehttp://xkcd.com/303/
© 2009 Howard M. Lewis Shiphttp://www.flickr.com/photos/hlship/3388927572/
© 2008 Howard M. Lewis Shiphttp://www.flickr.com/photos/hlship/3107467741/