More Related Content
Similar to Tapestry 5: Java Power, Scripting Ease (20)
More from Howard Lewis Ship (15)
Tapestry 5: Java Power, Scripting Ease
- 2. Howard Lewis Ship
• Creator, Apache Tapestry
• Author, "Tapestry in Action"
• Independent Consultant
2 © 2009 Howard M. Lewis Ship
- 4. Java
4 © 2009 Howard M. Lewis Ship
- 8. Concise
8 © 2009 Howard M. Lewis Ship
- 9. Fast!
9 © 2009 Howard M. Lewis Ship
- 12. Tapestry Templates
Login.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<body>
<h1>Please Login</h1>
Login
<t:form>
<t:label for="userId"/>
<t:textfield value="userId"/>
<br/>
form
<t:label for="password"/>
<t:passwordfield value="password"/>
<br/> label
<input type="submit" value="Login"/>
</t:form>
</html>
textfield
label
passwordfield
12 © 2009 Howard M. Lewis Ship
- 13. Page Classes
Login.tml
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<body>
<h1>Please Login</h1>
Login.java
<t:form>
<t:label for="userId"/> public class Login
<t:textfield value="userId"/> {
<br/> @Property
<t:label for="password"/> private String userId;
<t:passwordfield value="password"/>
<br/> @Property
<input type="submit" value="Login"/> private String password;
</t:form>
</html> Object onSuccess()
{
…
}
}
13 © 2009 Howard M. Lewis Ship
- 14. Page Flows
Login.java UserProfile.java
public class Login public class UserProfile
{ {
@Property …
private String userId; }
@Property
private String password;
void onValidate()
{
…
}
Object onSuccess()
{
…
return UserProfile.class;
}
}
14 © 2009 Howard M. Lewis Ship
- 15. Inversion of Control
Login.java
public class Login
Your
code
{
@Property
private String userId;
@Property
private String password;
… Inject IoC
@Inject
Service
private Session session; into field
@CommitAfter
Object onSuccess()
{
…
User user = (User) session. …
user.setLastLogin(new Date());
}
}
return UserProfile.class;
Tapestry
Services
15 © 2009 Howard M. Lewis Ship
- 16. Meta-Programming
Login.java
public class Login Generate getter & setter
{
@Property
private String userId;
@Property
private String password;
@InjectPage
private UserProfile userProfilePage;
…
@Inject
private Session session;
Commit Hibernate transaction
@CommitAfter
Object onSuccess()
{
…
User user = (User) session. …
user.setLastLogin(new Date());
return userProfilePage;
}
}
16 © 2009 Howard M. Lewis Ship
- 17. State Management
UserProfile.java
public class UserProfile
{ Shared global value (any page)
@Property
@SessionState
This page only private UserEntity user;
@Property
@Persist
private Date searchStart;
}
17 © 2009 Howard M. Lewis Ship
- 18. Template Injections
Component Meta-
Java Class
Programming
Message
Catalog
18 © 2009 Howard M. Lewis Ship
- 19. ❝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
19 © 2009 Howard M. Lewis Ship
- 21. 21 © 2009 Howard M. Lewis Ship
- 23. Index does not contain a property named 'now'
Available properties: class,
componentResources, currentTime
23 © 2009 Howard M. Lewis Ship
- 24. 24 © 2009 Howard M. Lewis Ship
- 25. 25 © 2009 Howard M. Lewis Ship
- 27. BoardGame.java
@Entity
public 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;
27 © 2009 Howard M. Lewis Ship
- 28. 28 © 2009 Howard M. Lewis Ship
- 29. Parameters
Property Types
BeanEditForm
Naming Conventions
Annotations
Explicit Overrides
Localized Messages
29 © 2009 Howard M. Lewis Ship
- 31. Flow
31 © 2009 Howard M. Lewis Ship
- 32. ❝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
32 © 2009 Howard M. Lewis Ship
- 34. 34 © 2009 Howard M. Lewis Ship
- 35. Index_de.properties
page-title=Erstellen Sie eine neue Brettspiel
add-game=Spiel hinzufŸgen
modern=Modernen Index.tml
medieval=Mittelalter
bible=Bibel <html t:type="layout" title="message:page-title"
abstract=Zusammenfassung xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">
war_game=Kriegsspiel
card=Karte <t:beaneditform submitlabel="message:add-game" object="game"/>
role_playing=Rollenspiele </html>
cooperative=Genossenschaft
creator-label=Schšpfer
publisher-label=Verlag
published-label=Veršffentlicht
inprint-label=Im Druck
theme-label=Thema
minplayers-label=Mindest-Spieler
maxplayers-label=Maximale Spieler
notes-label=Notation
35 © 2009 Howard M. Lewis Ship
- 37. Nested Components
Layout
title : String
Layout.tml
pageNames : List
pageName : String
<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> Index
</li>
</ul>
</div>
Layout
…
Loop PageLink
37 © 2009 Howard M. Lewis Ship
- 38. Component Parameters
Layout.java
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;
38 © 2009 Howard M. Lewis Ship
- 39. Non-Template Components
OutputDate.java
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));
}
}
39 © 2009 Howard M. Lewis Ship
- 40. 40 © 2009 Howard M. Lewis Ship
- 52. ❝Architecture is the decisions that you
wish you could get right early in a
project.❞
Martin Fowler, Chief Scientist, ThoughtWorks
52 © 2009 Howard M. Lewis Ship
- 54. 54 © 2009 Howard M. Lewis Ship
- 61. http://howardlewisship.com
Tapestry 5 Development and Support
On-site / Hands-on Tapestry Training
hlship@comcast.net
61 © 2009 Howard M. Lewis Ship
- 62. Image Credits
© 2006 Chris Walton
http://www.flickr.com/photos/philocrites/245011706/
© 2009 Nataline Fung
http://www.flickr.com/photos/metaphora/3384569933/
© 2006 Martino Sabia
http://www.flickr.com/photos/ezu/297634534/
© 2008 Alan Grinberg
http://www.flickr.com/photos/agrinberg/2465119180/
© 2008 Manu Gómez
http://www.flickr.com/photos/manugomi/2884678938/
© 2006 Tom Magliery
http://www.flickr.com/photos/mag3737/267638148/
© 2003 A. Lipson
http://www.andrewlipson.com/escher/relativity.html
© 2009 viernest
http://www.flickr.com/photos/viernest/3380560365/
© 2007 Jojo Cence
http://www.flickr.com/photos/jojocence/1372693375/
© 2007 Patrick Dirden
http://www.flickr.com/photos/sp8254/2052236004/
© 2009 Dani Ihtatho
http://www.flickr.com/photos/ihtatho/627226315/
62 © 2009 Howard M. Lewis Ship
- 63. Image Credits
© 2008 Christophe Delaere
http://www.flickr.com/photos/delaere/2514143242/
© 2007 Marina Campos Vinhal
http://www.flickr.com/photos/marinacvinhal/379111290/
© 2006 kris247
http://www.flickr.com/photos/kris247/86924080/
63 © 2009 Howard M. Lewis Ship