Your SlideShare is downloading. ×
0
Tapestry 5: Java
Power,
Scripting Ease
Howard M. Lewis Ship

TWD Consulting
hlship@comcast.net




                       ...
Howard Lewis Ship


• Creator, Apache Tapestry
• Author, "Tapestry in Action"
• Independent Consultant




               ...
What is Tapestry?




         3      © 2010 Howard M. Lewis Ship
Java
 4     © 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
Configuration
     8    © 2010 Howard M. Lewis Ship
Concise
   9   © 2010 Howard M. Lewis Ship
Fast!
  10    © 2010 Howard M. Lewis Ship
Mature
  11   © 2010 Howard M. Lewis Ship
Tapestry
Elements
       12   © 2010 Howard M. Lewis Ship
Tapestry Templates



        Login.tml

        <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
   ...
Page Classes


   Login.tml

   <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
     <body>
       <...
Page Flows

  Login.java                               UserProfile.java

  public class Login                       public ...
Inversion of Control
  Login.java

  public class Login
                                                              Your...
Meta-Programming
 Login.java

 public class Login                Generate getter & setter
 {
   @Property
   private Strin...
State Management


                    UserProfile.java

                    public class UserProfile
                    {...
Template                             Injections



                  Component      Meta-
     Java Class
                ...
!Most software today is very much
like an Egyptian pyramid with
millions of bricks piled on top of each
other, with no str...
Developer
Productivity
         21    © 2010 Howard M. Lewis Ship
22   © 2010 Howard M. Lewis Ship
Live Class Reloading




            23         © 2010 Howard M. Lewis Ship
24   © 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, curre...
27   © 2010 Howard M. Lewis Ship
Scaffolding




              28   © 2010 Howard M. Lewis Ship
BoardGame.java

@Entity
public class BoardGame
{
  @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @NonVisual
  pr...
30   © 2010 Howard M. Lewis Ship
Parameters
    Property Types




                             BeanEditForm
    Naming Conventions



     Annotations



...
32   © 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 underst...
Internationalization




         36      © 2010 Howard M. Lewis Ship
37   © 2010 Howard M. Lewis Ship
Index_de.properties

page-title=Erstellen Sie eine neue Brettspiel
add-game=Spiel hinzufŸgen
game-added=Added Brettspiel  ...
Tapestry
Components




       39    © 2010 Howard M. Lewis Ship
Nested Components
                                                                     Layout
                            ...
Layout Components
Layout.tml


<html xmlns="http://www.w3.org/1999/xhtml"                           $
  xmlns:t="http://ta...
Component Parameters

   Layout.java


   public class Layout
   {
     /** The page title, for the <title> element and th...
Non-Template Components



  OutputDate.java


  public class OutputDate
  {
    private final DateFormat formatter =
    ...
Start




           SetupRender
                                                      Component Rendering
               ...
45   © 2010 Howard M. Lewis Ship
46   © 2010 Howard M. Lewis Ship
Partial Page Updates
Games.tml

                                        Games.tml
<t:actionlink t:id="selectGame"
  contex...
Encapsulation

      48   © 2010 Howard M. Lewis Ship
Tapestry
Performance




        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
Scalability
55          © 2010 Howard M. Lewis Ship
JavaScript
Aggregation
     56   © 2010 Howard M. Lewis Ship
Far Future
 Expires
 Header
    57   © 2010 Howard M. Lewis Ship
Caching
   58   © 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, T...
Conclusion




         61   © 2010 Howard M. Lewis Ship
62   © 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


            •Downloads
            •Mailing Lists
            •Component Reference
          ...
http://jumpstart.doublenegative.com.au/




                       •Application Skeleton
                       •Detailed ...
http://chenillekit.codehaus.org/




            69            © 2010 Howard M. Lewis Ship
http://github.com/hlship/t5intro




              70          © 2010 Howard M. Lewis Ship
http://howardlewisship.com




    Tapestry 5 Development and Support
   On-site / Hands-on Tapestry Training
            ...
Image Credits
   © 2006 Chris Walton
   http://www.flickr.com/photos/philocrites/245011706/

                              ...
Image Credits
   © 2008 Christophe Delaere
   http://www.flickr.com/photos/delaere/2514143242/

                           ...
Upcoming SlideShare
Loading in...5
×

Codemash-Tapestry.pdf

2,888

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,888
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
40
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Codemash-Tapestry.pdf"

  1. 1. Tapestry 5: Java Power, Scripting Ease Howard M. Lewis Ship TWD Consulting hlship@comcast.net 1 © 2010 Howard M. Lewis Ship
  2. 2. Howard Lewis Ship • Creator, Apache Tapestry • Author, "Tapestry in Action" • Independent Consultant 2 © 2010 Howard M. Lewis Ship
  3. 3. What is Tapestry? 3 © 2010 Howard M. Lewis Ship
  4. 4. Java 4 © 2010 Howard M. Lewis Ship
  5. 5. Open Source 5 © 2010 Howard M. Lewis Ship
  6. 6. Component Based 6 © 2010 Howard M. Lewis Ship
  7. 7. Developer Focused 7 © 2010 Howard M. Lewis Ship
  8. 8. Convention over Configuration 8 © 2010 Howard M. Lewis Ship
  9. 9. Concise 9 © 2010 Howard M. Lewis Ship
  10. 10. Fast! 10 © 2010 Howard M. Lewis Ship
  11. 11. Mature 11 © 2010 Howard M. Lewis Ship
  12. 12. Tapestry Elements 12 © 2010 Howard M. Lewis Ship
  13. 13. 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 13 © 2010 Howard M. Lewis Ship
  14. 14. 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() { … } } 14 © 2010 Howard M. Lewis Ship
  15. 15. 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; } } 15 © 2010 Howard M. Lewis Ship
  16. 16. 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 16 © 2010 Howard M. Lewis Ship
  17. 17. 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; } } 17 © 2010 Howard M. Lewis Ship
  18. 18. 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; } 18 © 2010 Howard M. Lewis Ship
  19. 19. Template Injections Component Meta- Java Class Programming Message Catalog 19 © 2010 Howard M. Lewis Ship
  20. 20. !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
  21. 21. Developer Productivity 21 © 2010 Howard M. Lewis Ship
  22. 22. 22 © 2010 Howard M. Lewis Ship
  23. 23. Live Class Reloading 23 © 2010 Howard M. Lewis Ship
  24. 24. 24 © 2010 Howard M. Lewis Ship
  25. 25. Non-Tapestry Exception Reporting 25 © 2010 Howard M. Lewis Ship
  26. 26. Index does not contain a property named 'now' Available properties: class, componentResources, currentTime 26 © 2010 Howard M. Lewis Ship
  27. 27. 27 © 2010 Howard M. Lewis Ship
  28. 28. Scaffolding 28 © 2010 Howard M. Lewis Ship
  29. 29. 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; 29 © 2010 Howard M. Lewis Ship
  30. 30. 30 © 2010 Howard M. Lewis Ship
  31. 31. Parameters Property Types BeanEditForm Naming Conventions Annotations Explicit Overrides Localized Messages 31 © 2010 Howard M. Lewis Ship
  32. 32. 32 © 2010 Howard M. Lewis Ship
  33. 33. Feedback & Exploration 33 © 2010 Howard M. Lewis Ship
  34. 34. Flow 34 © 2010 Howard M. Lewis Ship
  35. 35. !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
  36. 36. Internationalization 36 © 2010 Howard M. Lewis Ship
  37. 37. 37 © 2010 Howard M. Lewis Ship
  38. 38. Index_de.properties page-title=Erstellen Sie eine neue Brettspiel add-game=Spiel hinzufŸgen game-added=Added Brettspiel Index.tml <html t:type="layout" title="message:page-title" modern=Modernen xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" medieval=Mittelalter xmlns:p="tapestry:parameter"> bible=Bibel abstract=Zusammenfassung <strong>${message}</strong> war_game=Kriegsspiel <t:beaneditform submitlabel="message:add-game" object="game" /> card=Karte 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 38 © 2010 Howard M. Lewis Ship
  39. 39. Tapestry Components 39 © 2010 Howard M. Lewis Ship
  40. 40. 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 Render property pageName 40 © 2010 Howard M. Lewis Ship
  41. 41. Layout Components Layout.tml <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/> % . . . ' Index.tml </body> </html> <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> 41 © 2010 Howard M. Lewis Ship
  42. 42. 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; 42 © 2010 Howard M. Lewis Ship
  43. 43. 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)); } } 43 © 2010 Howard M. Lewis Ship
  44. 44. Start SetupRender Component Rendering true OutputDate.java false BeginRender void beginRender(MarkupWriter writer) true false { writer.write(formatter.format(date)); } Render Template Render Body false AfterRender false true CleanupRender true End 44 © 2010 Howard M. Lewis Ship
  45. 45. 45 © 2010 Howard M. Lewis Ship
  46. 46. 46 © 2010 Howard M. Lewis Ship
  47. 47. Partial Page Updates Games.tml Games.tml <t:actionlink t:id="selectGame" context="game" zone="gameDetail"> <t:zone id="gameDetail" t:id="gameDetail"> ${game.title} <t:if test="selectedGame"> </t:actionlink> <strong>${selectedGame.title}</strong> by <strong>${selectedGame.creator}</strong> <br /> For ${selectedGame.minPlayers} - ↵ .../games.selectGame/3 ${selectedGame.maxPlayers} players. </t:if> </t:zone> Games.java @Property private BoardGame game, selectedGame; @InjectComponent private Zone gameDetail; Object onActionFromSelectGame(BoardGame game) { selectedGame = game; return gameDetail.getBody(); } 47 © 2010 Howard M. Lewis Ship
  48. 48. Encapsulation 48 © 2010 Howard M. Lewis Ship
  49. 49. Tapestry Performance 49 © 2010 Howard M. Lewis Ship
  50. 50. Request Processing Speed 50 © 2010 Howard M. Lewis Ship
  51. 51. Java == Fast 51 © 2010 Howard M. Lewis Ship
  52. 52. No Reflection 52 © 2010 Howard M. Lewis Ship
  53. 53. Page Pooling 53 © 2010 Howard M. Lewis Ship
  54. 54. GZIP Compression 54 © 2010 Howard M. Lewis Ship
  55. 55. Scalability 55 © 2010 Howard M. Lewis Ship
  56. 56. JavaScript Aggregation 56 © 2010 Howard M. Lewis Ship
  57. 57. Far Future Expires Header 57 © 2010 Howard M. Lewis Ship
  58. 58. Caching 58 © 2010 Howard M. Lewis Ship
  59. 59. Content Delivery Network 59 © 2010 Howard M. Lewis Ship
  60. 60. !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
  61. 61. Conclusion 61 © 2010 Howard M. Lewis Ship
  62. 62. 62 © 2010 Howard M. Lewis Ship
  63. 63. Infrastructure 63 © 2010 Howard M. Lewis Ship
  64. 64. Performance 64 © 2010 Howard M. Lewis Ship
  65. 65. Tapestry: The Expert is Built In 65 © 2010 Howard M. Lewis Ship
  66. 66. Tapestry 5 In Production 66 © 2010 Howard M. Lewis Ship
  67. 67. http://tapestry.apache.org •Downloads •Mailing Lists •Component Reference •User's Guide •Wiki 67 © 2010 Howard M. Lewis Ship
  68. 68. http://jumpstart.doublenegative.com.au/ •Application Skeleton •Detailed tutorials 68 © 2010 Howard M. Lewis Ship
  69. 69. http://chenillekit.codehaus.org/ 69 © 2010 Howard M. Lewis Ship
  70. 70. http://github.com/hlship/t5intro 70 © 2010 Howard M. Lewis Ship
  71. 71. http://howardlewisship.com Tapestry 5 Development and Support On-site / Hands-on Tapestry Training hlship@comcast.net 71 © 2010 Howard M. Lewis Ship
  72. 72. Image Credits © 2006 Chris Walton http://www.flickr.com/photos/philocrites/245011706/ © 2010 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 © 2010 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/ © 2010 Dani Ihtatho http://www.flickr.com/photos/ihtatho/627226315/ 72 © 2010 Howard M. Lewis Ship
  73. 73. 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/ © Randal Munroe http://xkcd.com/303/ © 2010 Howard M. Lewis Ship http://www.flickr.com/photos/hlship/3388927572/ © 2008 Howard M. Lewis Ship http://www.flickr.com/photos/hlship/3107467741/ 73 © 2010 Howard M. Lewis Ship
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×