Struts 2 – Das Imperium schlägt zurück?

Transcrição

Struts 2 – Das Imperium schlägt zurück?
Struts 2 –
Das Imperium schlägt
zurück?
Tobias Kieninger
<[email protected]>
Orientation in Objects GmbH
Weinheimer Str. 68
68309 Mannheim
www.oio.de
[email protected]
Java, XML und Open Source seit 1998
) Projekte )
• Schlüsselfertige Realisierung
von Software
• Unterstützung laufender
Projekte
• Pilot- und Migrationsprojekte
© 2008 Orientation in Objects GmbH
) Beratung )
) Akademie )
• Methoden, Standards und
• Schulungen, Coaching,
Tools für die Entwicklung
von offenen, unternehmensweiten Systemen
Weiterbildungsberatung,
Train & Solve-Programme
Struts 2 – Das Imperium schlägt zurück?
2
1
regnineik saibot - meine Wenigkeit
• J2EE / Java EE seit 2001
• Erstes Struts Seminar Dez. 2002
• Bis vor einem Jahr noch mehrere Seminare
• Einige Projekte
Tobias Kieninger
<kieninger(bei)oio.de>
• Struts ist „old-school“, ich bin „old-school“!?!
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
3
Struts 2 – Das Imperium schlägt zurück?
4
Gliederung
•
•
•
•
Warum wir hier sind
Erster Kontakt
Migration impossible?
Resümee
© 2008 Orientation in Objects GmbH
2
Warum wir „nicht“ hier sind!
•
•
•
•
„Welches ist das beste Webframework?“
„Ich mag Annotations nicht.“ / „Puhh, schon wieder XML-Hölle“
„Ist Struts2 besser als JSF?“
„Grails ist viel cooler…“
• „Hier werden Sie geholfen“
– Vortrag: Hilfe, ich soll ein Web Framework auswählen!
(Thilo Frotscher)
– War Mi. 08:30 Uhr
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
5
Struts 1
• Historie
– Struts 1.0.2 Feb 2002
– Struts 1.1 Juni 2003
– Bis heute Struts 1.3.8 (März 2007)
• Vorteile
– Lange Zeit defacto Standard
– Grosse Community und flächendeckender Einsatz
• Nachteile
–
–
–
–
ActionForms sind unbeliebt
Zu wenig Pojofiziert
Wird oft als „Tod“ bezeichnet
Actions kaum testbar
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
6
3
Struts 2 – Ein junges altes Framework
• Kombination aus Struts und OpenSymphony Webwork
• Voraussetzungen:
– Servlet API 2.4
– JSP API 2.0
– Java 5
• Aktuelle Version 2.0.11.1
– März 08
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
7
Struts 2 – Das Imperium schlägt zurück?
8
Verbesserungen in Struts 2
•
•
•
•
•
•
•
•
•
•
•
POJOs, juhu!
Mehr Flexibiltät bei der Ausgabe
Gute Standardeinstellungen
Java 5 Annotations sind möglich
Die unbeliebten ActionForms sind weg
Stateful Checkboxes
Einfache PlugIns
Guter AJAX Support
Einfaches Profiling
Verbesserte Testbarkeit
…
© 2008 Orientation in Objects GmbH
4
Gliederung
•
•
•
•
Warum wir hier sind
Erster Kontakt
Migration impossible?
Resümee
Struts 2 – Das Imperium schlägt zurück?
© 2008 Orientation in Objects GmbH
9
1001 Frameworks…
Servlet Engine
Servlet
JSP
Action
XSLT
Template
Action
Model
Struts
Cocoon
Webmacro
Webwork
....
Service
Service
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
10
5
Lifecycle Struts 1
Servlet Container
Request
Action
ActionServlet
Business Logik
Bean
Bean
Bean
FormBean
Response
JSP
Struts1 Taglibs
Bean
Struts 2 – Das Imperium schlägt zurück?
© 2008 Orientation in Objects GmbH
11
Lifecycle Struts 2
Servlet Container
Action
Interceptor
Response
Struts 2 FilterDispatcher
Request
View
Struts2 Tags
JSP
Business Logik
Action
Model
…
Value Stack
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
12
6
Struts 1 - ActionForm
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
13
Struts 1 - Action
public class LoginAction extends Action {
public ActionForward execute(ActionMapping
mapping, ActionForm form, HttpServletRequest req,
HttpServletResponse res){
try {
if(form instanceof LoginForm)
{
LoginForm lf = (LoginForm) form;
...
}
return mapping.findForward(SUCCESS);
}
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
14
7
Struts 2 - Action
public class LoginAction extends ExampleSupport {
private String username;
private String password;
public String execute() throws Exception {
if (isInvalid(...)) return INPUT;
return SUCCESS;
}
public void getUsername() { ...}
public void setUsername(String username) { ...}
...
}
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
15
Struts 2 – Das Imperium schlägt zurück?
16
Struts 1 - struts-config.xml
© 2008 Orientation in Objects GmbH
8
Struts 2 - struts.xml
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
17
Struts 2 – Das Imperium schlägt zurück?
18
Struts 1 - View
© 2008 Orientation in Objects GmbH
9
Struts 2 - View
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
19
Struts 2 – Das Imperium schlägt zurück?
20
Validierung
© 2008 Orientation in Objects GmbH
10
Internationalisierung
Struts 2 – Das Imperium schlägt zurück?
© 2008 Orientation in Objects GmbH
21
Interceptoren
• Komponente wird vor und nach der Verarbeitung aufgerufen
• Muss threadsave sein
• Wird verwendet für
© 2008 Orientation in Objects GmbH
Interceptor
Validierung
Doppelten Submit verhindern
Authentifizierung
Typkonvertierung
Session Handling
Debugging
FileUpload
ExcecAndWait
…
FilterDispatcher
–
–
–
–
–
–
–
–
–
…
Struts 2 – Das Imperium schlägt zurück?
22
11
Was isch denn hier
passiert?
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
23
Struts 2 – Das Imperium schlägt zurück?
24
PlugIns
© 2008 Orientation in Objects GmbH
12
Annotations
• Java 5 Annotations alternativ zu XML?
• Vier Ansatzpunkte bei Struts 2
– Action Annotations
– Interceptor Annotations
– Validation Annotations
– Type Conversion Annotations
• Bsp:
@Result(name="success", value="/example/HelloWorld.jsp")
public class HelloWorld extends ExampleSupport {
// ...
© 2008 Orientation in Objects GmbH
28.04.2008
25
Ajax
• Gute Unterstützung von dojo
• Ein paar Basis Features
–
–
–
–
–
–
–
Autocompleter
Datetime Picker
Asynchroner Submit
Textarea für HTML Formatierung
Tabbed Panel
Tree
…
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
26
13
JSF Integration mit dem JSF Plugin
• Einbinden von JSF Komponenten möglich
– Eigener JSF Interceptor Stack
• Verwendung von Actions
– Navigation verbleibt bei Struts
• Bisher wenig Dokumenation
– Showcase ist da
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
27
Struts 2 – Das Imperium schlägt zurück?
28
Gliederung
•
•
•
•
Warum wir hier sind
Erster Kontakt
Migration impossible?
Resümee
© 2008 Orientation in Objects GmbH
14
Struts 1 -> Struts 2
Struts 1
Action
ActionForm
ActionForward
struts-config.xml
ActionServlet
RequestProcessor
validation.xml
Struts 2
Action
Action or POJO’s
Result
struts.xml
FilterDispatcher
Interceptors
<Action>-validation.xml
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
29
Migration possible?
• Ist die Migration zu Struts 2
– Einfach?
– Sinnvoll?
• Strategien spärlich
– Struts 2 parallel zu Struts 1
– Schreib es neu!
– Nimm den “conversion wizard”…
• Migration Tutorials sind ergiebiger
Quelle: http://struts.apache.org/2.0.11.1/docs/migration-strategies.html
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
30
15
Migration by Ted Husted
• Is it difficult to migrate from Struts1 to Struts 2?
– Antwort: „somewhat!“
• The work itself is not difficult
• The effort is non-trivial
• Existing apps that will not change,
migration may not be worth the effort
• Apps that will change and grow,
the time will be well spent.
Quelle: http://opensource.atlassian.com/confluence/oss/display/STRUTS/Migrating%20Tutorial
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
31
Struts 2 – Das Imperium schlägt zurück?
32
Gliederung
•
•
•
•
Warum wir hier sind
Erster Kontakt
Migration impossible?
Resümee
© 2008 Orientation in Objects GmbH
16
Ein paar Zahlen
• Stellenausschreibungen monster.de zum 23.04.2008
– Struts: 186
– JSF: 144
– Struts 2: 0
• Freiberuflerbörse Gulp (März 2007- April 2008):
Freiberufler
Projektanfragen
Angebotene Projekte
Struts 1
Struts 2
JSF
1348
2767
416
5
5
4
1175
2216
328
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
33
Und nun?
• Webframeworkwahl insgesamt schwierig
• Viele neue Möglichkeiten mit Struts 2
– Für Struts 1 Entwickler ein Schritt nach vorn
• Noch zu wenig Dokumentation
• Ist Struts 2 das Richtige für Sie?
–
–
–
–
Welcher Typ Anwendung wird benötigt?
Welche Features werden benötigt?
Vorkenntnisse der Entwickler?
Wie entwickelt sich die Community?
© 2008 Orientation in Objects GmbH
Struts 2 – Das Imperium schlägt zurück?
34
17
Literaturhinweise
• Practical Apache Struts 2
– Sprache: Englisch
338 Seiten - Apress
Erscheinungsdatum: Nov 2007
ISBN: 1590599039
• Starting Struts 2
– Sprache: Englisch
120 Seiten - Lulu.com
Erscheinungsdatum: Juni 2007
ISBN: 1430320338
– Frei als PDF unter:
http://www.infoq.com/minibooks/starting-struts2
© 2008 Orientation in Objects GmbH
35
Persistenz mit Hibern
Links
• Struts 2
http://struts.apache.org/2.0.11.1/index.html
• Migrating to Struts 2 (Ted Husted)
http://www.strutsuniversity.org/Migrating%20Tutorial
• Migrating Applications to Struts 2 (Ian Roughley)
http://www.infoq.com/news/migrating-struts2
© 2008 Orientation in Objects GmbH
36
Persistenz mit Hibern
18
? ? ?
?
?
Fragen ?
Orientation in Objects GmbH
Weinheimer Str. 68
68309 Mannheim
Tobias Kieninger
<[email protected]>
www.oio.de
[email protected]
Vielen Dank für Ihre
Aufmerksamkeit !
Orientation in Objects GmbH
Weinheimer Str. 68
68309 Mannheim
Tobias Kieninger
<[email protected]>
www.oio.de
[email protected]
19