Apache Tapestry Jan Diller Java Architekt Alternatives Konzept zur Web-Anwendungsentwicklung Nur eine Folie: Wer ist t&p?
gegründet 1991
60 MitarbeieterInnen
Bochum und Bern
2/47 Gliederung
Vortrag Tapestry
● Wir haben nur 45min Zeit. ● Wir machen keine Pause. ● Wir haben eine Progress-Bar.
3/47 Einleitung
Alternative? Wozu?
● 'Verbreitung von Web-Frameworks' – Es gibt sehr viel mehr Frameworks als man denkt. – Wikipedia listet 105 Webframeworks. – Neben solchen in Java gesellen sich auch noch welche in .net, PHP, Python und Perl dazu. – Immerhin noch 22 Frameworks in Java.
4/47 Einleitung
Web-Applikation Techologien s s k e s r a e n c e o r s c o y a o c t r g r a a o F a a u y f t W j F r r c e F b … e h t t b o 4 o y o c s k e J S m i i e T c C M … r i M R p W P a W T
JSP JSF <*.jsp>/<*.xhtml>
Servlets
5/47 Einleitung
web.xml
....
6/47 Einleitung
web.xml
....
Components
8/47 Einleitung
Components
9/47 Einleitung
Components
10/47 Einleitung
Components
11/47 Einleitung
Components
12/47 Einleitung
Support
13/47 Einleitung
Verschiedene Web-Frameworks auf dem Zeitstrahl
14/47 Einleitung
Warum sollte ich Tapestry verwenden – eine Sammlung ● … weil es performant ist.
● … weil es schnell und einfach zu lernen ist.
● … weil es ausgewogen und vollständig ist.
● … weil man als Entwickler mehr als ein Web-Framework kennen sollte.
http://de.slideshare.net/mraible/comparing-jsf-spring-mvc-stripes-struts-2-tapestry-an d-wicket-presentation http://docs.codehaus.org/pages/viewpage.action?pageId=190316696
15/47 Einleitung
Warum sollte ich Tapestry verwenden – eine Sammlung ● … there's magic and metaprogramming happening everywhere. You could argue it's overdoing convention over configuration.
● … simple stuff is very simple to do, harder stuff requires you to understand in detail how Tapestry 5 works and can be hard if you don't (yet).
● Most important Tapestry 5 feature for me is the flexibility of the framework. You can override almost every piece of code inside Tapestry's core, thanks to Tapestry IoC.
● Tapestry has beautiful URLs. package/page/${param1}/$ {param2} http://stackoverflow.com/questions/3831807/java-server-faces-2-0-or-tapestry-5-2
16/47 Einleitung
Info-Quellen - Jumpstart
● Tomcat 7 ● JBoss 7 ● Glassfish 3.1.2
17/47 Einleitung
Info-Quellen – My First Tpy Project
18/47 Einleitung
Info-Quellen – My First Tpy Project mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org mvn jetty:run
19/47 Konzept
Was ist Tapestry?
Component oriented framework for creating dynamic, robust, highly scalable web applications in Java. Quelle: http://tapestry.apache.org/
20/47 Konzept
Wesentliche Konzepte
● Convention over Configuration
● Inversion of Control
21/47 Konzept
Convention over Configuration
src └───main ├───java │ └───com Convention over configuration │ └───tp │ └───doag2013 │ ├───components │ │ Layout.java │ │ │ ├───pages │ │ About.java │ │ Contact.java │ │ Index.java │ │ │ └───services │ AppModule.java │ DevelopmentModule.java │ QaModule.java │ ├───resources │ └───com │ └───tp │ └───doag2013 │ ├───components │ │ Layout.tml │ │ │ └───pages │ About.tml │ Contact.tml │ Index.properties │ Index.tml │ └───webapp ├───layout │ │ layout.css │ │ │ └───images └───WEB-INF 22/47 app.properties web.xml Konzept
Convention over Configuration
target │ ├───layout │ │ layout.css Convention over configuration │ │ │ └───images │ ├───META-INF └───WEB-INF │ app.properties │ web.xml │ └───classes │ └───com └───tp └───doag2013 └───tpy ├───components │ Layout.class │ Layout.tml │ ├───pages │ About.class │ About.tml │ Contact.class │ Contact.tml │ Index.class │ Index.properties │ Index.tml │ └───services AppModule.class DevelopmentModule.class QaModule.class
23/47 Konzept
CoC-Container – Fügt zusammen was zusammen gehört
CoC-Container Presentation XHTML <*.tml> Components Mixins
Controller <*.java>
24/47 Konzept
Convention over Configuration
src src └───main └───main ├───java ├───java │ └───com │ └───com │ └───tp │ └───tp │ └───doag2013 │ └───doag2013 │ ├───components │ HelloWorldController.java │ │ Layout.java │ │ │ └───webapp │ ├───pages │ helloWorld.xhtml │ │ About.java │ index.html │ │ Contact.java │ page2.xhtml │ │ Index.java │ │ │ ├───resources │ └───services │ └───css │ AppModule.java │ style.css │ DevelopmentModule.java │ │ QaModule.java └───WEB-INF │ faces-config.xml ├───resources web.xml │ └───com │ └───tp │ └───doag2013 │ ├───components │ │ Layout.tml │ │ │ └───pages │ About.tml │ Contact.tml │ Index.properties │ Index.tml │ └───webapp ├───layout │ │ layout.css │ │ │ └───images └───WEB-INF 25/47 app.properties web.xml Konzept
Convention over Configuration –
Rendering Phases
26/47 27/47 Konzept
Convention over Configuration - Alternative Schreibweisen -
● void cleanupRender() vs. @Cleanup
● void setupRender() vs. @SetupRender
● … id=“add“ ... void onActionFromAdd(int amount) vs. @OnEvent(value = "add") void doSomeAdding(int amount)
28/47 Konzept
Einreihung ins MVC-Konzept
Model
<@Application> <@Session> <@Page>
View
XHTML <*.tml> Controller Components Mixins <*.java>
29/47 Faktencheck
Bevor ein Framework verwendet wird ...
… sollte man sich diese Fragen beantworten! – Vertraue ich meinem Lieferanten? – Wie vital ist das Projekt? – Gibt es das Projekt noch in 3, 5, 10, 20 Jahren? ● Gibt es meine Anwendung bis dahin noch? – Wie viele Anwender wird meine Anwendung haben? – Werde ich von einer Community unterstützt und wenn ja, wie schnell erwarte/erhalte ich Antworten? – Ist mein Framework quelloffen?
30/47 Faktencheck
Der Lieferant - Apache Foundation
● Die Apache Software Foundation ist eine ehrenamtlich arbeitende Organisation zur Förderung der Apache-Softwareprojekte.
● Charakteristisch für Apache-Projekte ist der gemeinschaftliche und diskussionsfreudige Entwicklungsprozess und die offene und pragmatische Apache-Lizenz, welche auch von externen Open-Source-Projekten benutzt und angepasst werden kann.
● Zu den Aufgaben der ASF gehören der rechtliche Schutz aller Projekt-Mitarbeiter und der Schutz der Marke „Apache“. Quelle: Wikipedia
31/47 Faktencheck
Der Lieferant - Apache Foundation
● Aktuell wird an ca. 130 Projekten gearbeitet.
● Membership in The Apache Software Foundation is a privilege and is by invitation only. Candidates for membership are proposed by existing members, and voted upon by the existing membership.
● The Apache Software Foundation, a US 501(3)(c) non-profit corporation, provides organizational, legal, and financial support for a broad range of over 140 open source software projects. Quelle: http://apache.org/foundation/members.html
32/47 Faktencheck
Der Lieferant - Apache Foundation
● Build-Tools – Ant, Maven ● Web-Application-Frameworks – Struts, Tapestry, Turbine, Wicket, Tiles ● Web-Services – Axis, CXF ● Web-/Application-Server – Tomcat, TomEE, OpenEJB, Geronimo
33/47 Faktencheck
Vitalität – Releasezyklen
● 04.11.2013 5.4-alpha-24 ● 12.10.2012 5.3.6 ● 20.12.2011 5.3.1
● 11.10.2013 5.4-alpha-23 ● 30.08.2012 5.3.5 ● 22.06.2011 5.3.0
● 16.09.2013 5.4-alpha-22 ● 16.07.2012 5.3.4 ● 21.11.2011 5.3
● 12.09.2013 5.4-alpha-21 ● 20.03.2012 5.3.3 ● 29.06.2011 5.2.6
● 11.09.2013 5.4-alpha-20 ● 24.04.2012 5.3.3 ● 28.03.2011 5.2.5
● 10.09.2013 5.4-alpha-19 ● 07.02.2012 5.3.2 ● 08.01.2011 5.2.4
● 05.09.2013 5.4-alpha-18 ● 08.01.2011 5.2.2
● 05.09.2013 5.4-alpha-17 ● 08.01.2011 5.2.1
● 04.09.2013 5.4-alpha-16
● 29.04.2013 5.3.7
34/47 Faktencheck
Vitalität – Wer steckt hinter Tapestry Name ID role email address website Andreas Andreou andyhot PMC member [email protected] http://andyhot.gr Ben Dotte bdotte committer [email protected] Bob Harner bobharner committer [email protected] https://github.com/bobharner Christophe Cordenier ccordenier committer [email protected] http://spreadthesource.com Dan Adams dadams committer [email protected] Daniel Gredler gredler committer [email protected] Daniel Jue djue committer [email protected] David Solis dsolis committer [email protected] François Facon ffacon committer [email protected] http://people.apache.org/~ffacon/ Howard M. Lewis Ship hlship PMC chair [email protected] http://howardlewisship.com Igor Drobiazko drobiazko PMC member [email protected] http://tapestry5.de Jesse Kuhnert jkuhnert PMC member [email protected] Josh Canfield joshcanfield committer [email protected] Kalle Korhonen kaosko committer [email protected] http://tynamo.org Kevin Menard kmenard committer [email protected] Marcus Schulte mschulte PMC member [email protected] Massimo Lusetti mlusetti PMC member [email protected] http://meridio.blogspot.com Richard Lewis-Shell rlewisshell PMC member [email protected] Robert D. Zeigler robertdzeigler committer [email protected] Robin Komiwes robinkomiwes committer [email protected] http://spreadthesource.com Taha Hafeez tawus committer [email protected] http://tawus.wordpress.com Ted Steen tedst committer [email protected] Thiago H. de Paula Figueiredo thiagohp PMC member [email protected] Ulrich Stärk uli PMC member [email protected] 35/47 Konzept
Wesentliche Konzepte
● Convention over Configuration
● Inversion of Control
36/47 Konzept
IoC Registry
IoC - Inversion of Control (Steuerungsumkehr)
‚Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels. The question, is what aspect of control are they inverting?‘ Quelle: Martin Fowler
● In Tapestry wird hier drunter unter anderem die Möglichkeit verstanden, eigene Services zu registrieren und diese einfach in die Service-Consumer, also z.B. die Controller, zu injizieren.
37/47 Konzept
IoC Registry
● Tapestry ist um seine eigenen IoC Container gebaut.
● Verzicht auf Thirdparties wie Spring oder Guice.
● Dieser eigenen IoC Container ist Grundlage für die Stabilität, die Performance und die Erweiterbarkeit von Tapestry.
● Dadurch, dass der IoC Container schon im Entwurf enthalten ist, fällt es leicht, jeglichen eingebauten Service auf die Bedürfnisse des jeweiligen Projektes anzupassen oder zu erweitern.
38/47 Konzept
IoC Registry
● Merkmale des IoC Container – Konfiguration findet im Code, nicht in XML statt.
– Einfach Erweiterbarkeit von Services. – Eingebautes Aspekt orientiertes Programmier-Model. – Einfache Modularisierung.
39/47 Konzept
Injection
‚Tapestry tranforms your class at runtime. Further, an instance of the class is useless by itself, it must be wired together with its template and its sub-components.‘ Quelle: http://tapestry.apache.org/
40/47 Konzept
Injection
‚On top of that, Tapestry keeps just once instance of each page in memory (since 5.2). It reworks the bytecode of the components so that a single instance can be shared across multiple request handling threads.‘ Quelle: http://tapestry.apache.org/
41/47 Konzept
Injection
private Map
● stattdessen private Map
Page Navigation
● Null response public Object onAction(){ return null; }
● String response public String onAction(){ return "Index"; }
● Class response public Object onAction(){ return Index.class } 43/47 Konzept
Page Navigation
● Page response @InjectPage private Index index;
public Object onAction(){ return index; }
● HttpError public Object onAction(){ return new HttpError(302, "The Error message); } 44/47 Konzept
Page Navigation
● Link response – Verweis auf eine interne Resource
● Stream response – für PDF etc. ● URL response – Verweis auf eine externe Resource. ● Object response
- Rückgabe eine Fehlers.
45/47 Getting started
Hibernate Unterstützung src/pom.xml (partial)
src/main/resources/hibernate.cfg.xml
Fragen Sie gern Danke ! Stand 202
47/47