Struts 2 – Das Imperium schlägt zurück? - OIO · 2020-07-06 · Struts2 Tags Request Business...

19
Orientation in Objects GmbH Weinheimer Str. 68 68309 Mannheim www.oio.de [email protected] Tobias Kieninger <[email protected]> Struts 2 – Das Imperium schlägt zurück? © 2008 Orientation in Objects GmbH Java, XML und Open Source seit 1998 Struts 2 – Das Imperium schlägt zurück? 2 ) Akademie ) ) Beratung ) Schulungen, Coaching, Weiterbildungsberatung, Train & Solve-Programme Methoden, Standards und Tools für die Entwicklung von offenen, unternehmens- weiten Systemen Schlüsselfertige Realisierung von Software Unterstützung laufender Projekte Pilot- und Migrationsprojekte ) Projekte )

Transcript of Struts 2 – Das Imperium schlägt zurück? - OIO · 2020-07-06 · Struts2 Tags Request Business...

1

Orientation in Objects GmbH

Weinheimer Str. 6868309 Mannheim

[email protected]

Tobias Kieninger <[email protected]>

Struts 2 –Das Imperium schlägt

zurück?

© 2008 Orientation in Objects GmbH

Java, XML und Open Source seit 1998

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

) Akademie )) Beratung )

• Schulungen, Coaching, Weiterbildungsberatung, Train & Solve-Programme

• Methoden, Standards und Tools für die Entwicklung von offenen, unternehmens- weiten Systemen

• Schlüsselfertige Realisierung von Software• Unterstützung laufender Projekte• Pilot- und Migrationsprojekte

) Projekte )

2

© 2008 Orientation in Objects GmbH

regnineik saibot - meine Wenigkeit

• J2EE / Java EE seit 2001

• Erstes Struts Seminar Dez. 2002• Bis vor einem Jahr noch mehrere Seminare• Einige Projekte

• Struts ist „old-school“, ich bin „old-school“!?!

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

Tobias Kieninger <kieninger(bei)oio.de>

© 2008 Orientation in Objects GmbH

Gliederung

• Warum wir hier sind• Erster Kontakt• Migration impossible?• Resümee

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

3

© 2008 Orientation in Objects GmbH Struts 2 – Das Imperium schlägt zurück? 5

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? 6

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

4

© 2008 Orientation in Objects GmbH Struts 2 – Das Imperium schlägt zurück? 7

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? 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• …

5

© 2008 Orientation in Objects GmbH

Gliederung

• Warum wir hier sind• Erster Kontakt• Migration impossible?• Resümee

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

© 2008 Orientation in Objects GmbH

1001 Frameworks…

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

Servlet Engine

ActionAction

StrutsCocoon

WebmacroWebwork

....

Servlet

XSLT

JSP

Template

ServiceModelService

6

© 2008 Orientation in Objects GmbH Struts 2 – Das Imperium schlägt zurück? 11

Servlet Container

Lifecycle Struts 1

JSP

ActionServlet Action

FormBean

Struts1 Taglibs

Business LogikRequest

ResponseBean

BeanBean Bean

© 2008 Orientation in Objects GmbH Struts 2 – Das Imperium schlägt zurück? 12

Servlet Container

Lifecycle Struts 2

ViewJSP

Struts 2 FilterD

ispatcher

Action

Struts2 Tags

Business LogikRequest

Response

Interceptor

Value Stack

Action

Model

7

© 2008 Orientation in Objects GmbH

Struts 1 - ActionForm

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

© 2008 Orientation in Objects GmbH

Struts 1 - Action

public class LoginAction extends Action {

public ActionForward execute(ActionMappingmapping, ActionForm form, HttpServletRequest req,HttpServletResponse res){

try { if(form instanceof LoginForm) { LoginForm lf = (LoginForm) form; ... } return mapping.findForward(SUCCESS);}

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

8

© 2008 Orientation in Objects GmbH

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) { ...} ...

}

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

© 2008 Orientation in Objects GmbH

Struts 1 - struts-config.xml

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

9

© 2008 Orientation in Objects GmbH

Struts 2 - struts.xml

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

© 2008 Orientation in Objects GmbH

Struts 1 - View

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

10

© 2008 Orientation in Objects GmbH

Struts 2 - View

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

© 2008 Orientation in Objects GmbH

Validierung

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

11

© 2008 Orientation in Objects GmbH

Internationalisierung

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

© 2008 Orientation in Objects GmbH

Interceptoren

• Komponente wird vor und nach der Verarbeitung aufgerufen

• Muss threadsave sein

• Wird verwendet für– Validierung– Doppelten Submit verhindern– Authentifizierung– Typkonvertierung– Session Handling– Debugging– FileUpload– ExcecAndWait– …

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

FilterDispatcher

Interceptor

12

© 2008 Orientation in Objects GmbH

Was isch denn hierpassiert?

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

© 2008 Orientation in Objects GmbH

PlugIns

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

13

© 2008 Orientation in Objects GmbH28.04.2008 25

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 Struts 2 – Das Imperium schlägt zurück? 26

Ajax

• Gute Unterstützung von dojo

• Ein paar Basis Features– Autocompleter– Datetime Picker– Asynchroner Submit– Textarea für HTML Formatierung– Tabbed Panel– Tree– …

14

© 2008 Orientation in Objects GmbH

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

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

© 2008 Orientation in Objects GmbH

Gliederung

• Warum wir hier sind• Erster Kontakt• Migration impossible?• Resümee

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

15

© 2008 Orientation in Objects GmbH

Struts 1 -> Struts 2

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

Struts 1 Struts 2Action ActionActionForm Action or POJO’sActionForward Resultstruts-config.xml struts.xmlActionServlet FilterDispatcherRequestProcessor Interceptorsvalidation.xml <Action>-validation.xml

© 2008 Orientation in Objects GmbH

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

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

16

© 2008 Orientation in Objects GmbH

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

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

© 2008 Orientation in Objects GmbH

Gliederung

• Warum wir hier sind• Erster Kontakt• Migration impossible?• Resümee

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

17

© 2008 Orientation in Objects GmbH

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):

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

Struts 1 Struts 2 JSFFreiberufler 1348 5 1175Projektanfragen 2767 5 2216Angebotene Projekte 416 4 328

© 2008 Orientation in Objects GmbH

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?

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

18

© 2008 Orientation in Objects GmbH 35 Persistenz mit Hibern

Literaturhinweise

• Practical Apache Struts 2– Sprache: Englisch

338 Seiten - ApressErscheinungsdatum: Nov 2007ISBN: 1590599039

• Starting Struts 2– Sprache: Englisch

120 Seiten - Lulu.comErscheinungsdatum: Juni 2007ISBN: 1430320338

– Frei als PDF unter:http://www.infoq.com/minibooks/starting-struts2

© 2008 Orientation in Objects GmbH 36 Persistenz mit Hibern

Links

• Struts 2http://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

19

Orientation in Objects GmbH

Weinheimer Str. 6868309 Mannheim

[email protected]

Tobias Kieninger <[email protected]>

? ?

???

Fragen ?

Orientation in Objects GmbH

Weinheimer Str. 6868309 Mannheim

[email protected]

Tobias Kieninger <[email protected]>

Vielen Dank für IhreAufmerksamkeit !