39
Apache Shale Was ist Apache Shale ?

Apache Shale

Embed Size (px)

DESCRIPTION

German talk on Shale

Citation preview

Page 1: Apache Shale

Apache Shale

Was ist Apache Shale ?

Page 2: Apache Shale

2

Apache ShaleMatthias Weßendorf, Oracle Corp.

Table of Content

• Struts und Shale• Shale – Ein Framework für JSF• Bestandteile von Shale

• Vorstellung der Shale Module

• Zukunft• WebBeans• JavaServer Faces 2.0

Page 3: Apache Shale

3

Apache ShaleMatthias Weßendorf, Oracle Corp.

Struts und Shale

• Gründer: Craig McClanahan• Shale war! Ein Struts-Unterprojekt

• Struts 2.0 ? „The next Struts“ (David Geary)

• Struts:• Action-basiert (auch in Struts2, aka WebWork)

• Shale:• JSF-zentriert, Services/AddOns für JSF

Page 4: Apache Shale

4

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale Framework• JavaServer Faces:

• API für „UI components“ • leichtgewichtiges Framework (erweiterbar)

• Shale:• Modernes Web Anwendungs Framework für JSF 1.x …• Sammlung lose gekoppelte Services

• Je nach Notwendigkeit kombinierbar• Unterstützt JSF bei der Überbrückung von „Lücken“

• Open Source („Speed boat“) vs. Spezifikation („Schnecke“)

Page 5: Apache Shale

5

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Bestandteile (I)

• Application Controller• Clay-Plugin• Dialog Manager• Remoting• Spring-Integration

Page 6: Apache Shale

6

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Bestandteile (II)

• Test-Framework• Tiles Integration• Tiger• Validator Support• View Contoller

Page 7: Apache Shale

7

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Application Controller

• JSF ist page orientiert• Shale erweitert dieses sogar (view controller)

• Action-basiert kann auch hilfreich sein:• Anwendungs-Controller, der alle Anfragen behandelt• Anpassungsmöglichkeiten:

• Struts: RequestProcessor / Commons Chain (1.3)• JSF: PhaseListener

• Shale Application Controller:• Ausführung von „Commands“ vor und nach dem JSF-

Lifecycle

Page 8: Apache Shale

8

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Application Controller (II)

• Configuration:• web.xml:

Commons Chain & ShaleApplicationFilter • chain-config.xml: Commands

<catalog name="shale"> <chain name="preprocess"> (postprocess) <command className="..." /> </chain> ...

Page 9: Apache Shale

9

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Application Controller (III)

• Commands basieren auf Jakarta Commons Chain:

public class PostCommand implements Command{ public boolean execute(Context context)… { ShaleWebContext swc = (ShaleWebContext) context; //do some clean ups; return false; }}

Page 10: Apache Shale

10

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Application Controller (IV)

• ContextRelativePathFilter• Bestandteil von Shale

• Zugriff auf „Quellcodes“ verbieten (chain-config.xml):

<catalog name="shale"> <chain name="preprocess"> <command

className="org.apache.shale.application.ContextRelativePathFilter" includes="\S*\.xml,\S*\.faces,\S*\.html,\S*\.gif,\S*\.jpg,index\.jsp" excludes="\S*\.jsp ,\S*\.jspf ,\S*\.xhtml"/>

</chain> ...

Page 11: Apache Shale

11

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Clay-Plugin

• Temaplating Framework für JSF• Alternative zu Facelets und JSP(X)

• Tiles-ähnlicher als Facelets• Mehr XML files, als Facelets

• Configuration overhead ?!

• Beispiel

Page 12: Apache Shale

12

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Beispiel

• XML-Configs:• web.xml

• 3 Context-param Einträge

• clay-config.xml• Für Clay Komponenten

• clay-views-config.xmk• Seiten, die auf der/den Komponenten basieren

• gewöhnliche HTML Datei als Template

Page 13: Apache Shale

13

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Clay Komponenten<component jsfid="baseLayout" extends="clay" id="base">

<attributes><set name="clayJsfid" value="/templates/template.html" />

</attributes><symbols>

<set name="title" value="Hello World" /><set name="leftContent" value="/pages/defaultLeftNav.html" /><set name="headerContent" value="/pages/defaultHeader.html"

/><set name="bodyContent" value="/pages/defaultBody.html" /><set name="footerContent"

value="/pages/defaultFooter.html" /></symbols>

</component>

Page 14: Apache Shale

14

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Clay Views<component jsfid="/page1.jsf" extends="baseLayout">

<symbols><set name="title" value="Page 1" /><set name="bodyContent" value="/pages/page1Body.html"

/></symbols>

</component><component jsfid="/page2.jsf" extends="baseLayout">

<symbols><set name="title" value="Page 2" /><set name="bodyContent" value="/pages/page2Body.html"

/></symbols>

</component>

Page 15: Apache Shale

15

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – template.html<body><div id="head"><span jsfid="clay" clayjsfid="@headerContent"

allowbody="false">Header Content</span></div>

<div id="menu"><span jsfid="clay" clayjsfid="@leftContent"allowbody="false">Left Content</span></div>

<div id='content'><span jsfid="clay" clayjsfid="@bodyContent"allowbody="false">Body Content</span></div>

<div id="footer"><span jsfid="clay" clayjsfid="@footerContent"allowbody="false">Footer Content</span></div>

</body>

Page 16: Apache Shale

16

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Seite...<td> <input id="name" type="text" size="40" maxlength="50"

value="#{@managed-bean-name.person.name}"/></td>

...<td> <input type="submit" action="#{@managed-bean-name.sayHello}"

value="#{messages['page2.button.label']}"></td>...

Page 17: Apache Shale

17

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – BeispielHTML Mapping in „Clay Views“:

• <a> </a> • <form> </form> • <input type=txt> • <input type=checkbox> • <input type=radio> • <input type=submit> • <label> </label> • <select> </select> • <select multiple> </select> • <option> • <textarea> </textarea>

Page 18: Apache Shale

18

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Dialog Manager (I)• Erweiterung des JSF-NavigationHandler um Dialog /

Conversation• Wiederverwendung von „views“ in mehreren

„Klickstrecken“ mit Standard JSF schwer:• <h:commandButton rendered=„#{bogus}“ />

• Zwei Ausprägungen:• Basic – Einfache Implementierung • SCXML – W3C State Chart XML Implementation

• Basiert auf Jakarta SCXML

• Shale Dialog basiert auf der Idee vom Spring Web Flow

Page 19: Apache Shale

19

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Dialog Manager (II)

Page 20: Apache Shale

20

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Dialog Manager (III)

• Basic Dialog kennt vier Zustände:• Action

• Ausführen einer „Action-Methode“, via JSF MethodBinding

• View• JSF View (normale JSF seite mit Commands controls)

• End – s• Subdialog – Unterdialog, der„Auslöser“ wird

gespeichert.

• Beispiel

Page 21: Apache Shale

21

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Dialog Manager (IV)<dialog name="Impact" start=„kundenuebersicht"><!-- globale transitions --><transition outcome="start" target=„kundenuebersicht"/> <transition outcome="end" target="Exit"/> <view name=„kundenuebersicht" viewId="/kundenMaster.jsp"> <transition outcome="details" target=„kundedetail"/> <transition outcome="tree" target="treeview"/> </view> <view name=„kundedetail" viewId="/kundeDetail.jsp" />

<view name="treeview" viewId="/tree.jsp" /> <end name="Exit" viewId="/iahallo.jsp"/></dialog>

Page 22: Apache Shale

22

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Dialog Manager (V)

• Starten eines Dialogs• Navigation:

• Über Command Control• commandButton / commandLink

• „logical outcome“ => dialog:irgendwas• Prefix konfigurierbar*

Page 23: Apache Shale

23

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Dialog Manager (VI)

• Programmatically*

FacesContext context = FacesContext.getCurrentInstance();

DialogContextManager manager = (DialogContextManager) context.getApplication().getVariableResolver(). resolveVariable(context, Constants.MANAGER_BEAN);

DialogContext dcontext = manager.create(context, "foo");

dcontext.start(context); return null;

Page 24: Apache Shale

24

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Remoting (I)

• Abildung von Serverseitigen Ressourcen auf URLs

• Processor führt beliebige Aktionen aus:• Class Resource: JS oder CSS in JARs• Web Resource: JS oder CSS im Web-App. Root• Method Binding: Backing Bean Methode• Chain: Ein Jakarta Commons Chain Catalog

• Beispiel Method Binding

Page 25: Apache Shale

25

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Remoting (II)

Page 26: Apache Shale

26

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Remoting (III)JavaScript (mit Prototype Framework):

function validateUsername(username) {

new Ajax.Request( "dynamic/userBean/validateUsername.faces", { method: "post", parameters: "username=" + username, onComplete: showMessage //Callback } );}

Page 27: Apache Shale

27

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Remoting (IV)public void validateUsername() { FacesContext context = FacesContext.getCurrentInstance(); String username = (String)context .getExternalContext() .getRequestParameterMap().get("username");´ ... ResponseWriter writer = (new ResponseFactory()).getResponseWriter(context, "text/plain"); try { writer.writeText(text, null); } catch (IOException e) { e.printStackTrace(); }}

Page 28: Apache Shale

28

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Spring-Integration• Spring: DI / IoC container

• Support für JSF: DelegatingVariableResolver• faces-config.xml Eintrag notwendig

• Shale:• DelegatingVariableResolver automatisch aktiviert

• Zugriff auf WebApplicationContext:

WebApplicationContext wac = (WebApplicationContext) getValue("#{webApplicationContext}");

• Spring 1.x (1.0.x branch) und Spring 2.x (trunk)

Page 29: Apache Shale

29

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Test-Framework• JUnit-basiertes Testframework für JSF• Mock Objekte für JSF

• JMock support

• Testen von JSF Komponenten• Trinidad

• Testen von Shale• View Controller Support

• Testen von Implementierung• MyFaces

Page 30: Apache Shale

30

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – JMock Beispielpublic void testInvokeOnComp() throws Exception { UIForm form = new UIForm(); UIInput i1 = new UIInput(); i1.setId("_id1"); ... form.getChildren().add(i1);

this.facesContext.getViewRoot().getChildren().add(form);

Mock mock = mock(ContextCallback.class); ContextCallback cc = (ContextCallback) mock.proxy();

mock.expects(once()).method("invokeContextCallback").with(eq(facesContext), eq(i2));

this.facesContext.getViewRoot().invokeOnComponent(facesContext, i2.getClientId(facesContext), cc);

mock.verify(); }

Page 31: Apache Shale

31

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Tiles Integration

• Support für „standalone“ Tiles• Stellt JSF ViewHandler für Tiles bereit• Tiles:

• Templating Framework für JSP• Nicht entwickelt für JSF

• Clay oder Facelets• old school

• Interessant bei „Migration“ ?

Page 32: Apache Shale

32

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Tiger Extensions• Java5 Annotations für JSF:

• Managed Beans@Bean(name="mybean", scope=Scope.SESSION) public class MyBean...

• View Controller@View public class MyFooController ...

• Components@FacesComponent("my.component.type") public classMyComponent extends UIComponentBase ...

• web.xml Context-Parameter-Eintrag:org.apache.shale.tiger.SCAN_PACKAGES

Page 33: Apache Shale

33

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Validator Support (I)

• Client-side Validation (nicht Teil von JSF)• JSF nur wenig Validator-Komponenten

• aber API für eigene Validator-Komponenten

• Integriert Jakarta Commons Validator• Credit Card• Date (naja...)• Email• RegEpx, ...

• JSP Tags für Integration

Page 34: Apache Shale

34

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Validator Support (II)

<h:form onsubmit="return validateForm(this);"> <h:inputText ... <val:commonsValidator type="creditCard" arg="#{msgs.creditCardNumberPrompt}"

server="true" client="true"> </h:inputText> ...</h:form>

Page 35: Apache Shale

35

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – Validator Support (III)

• Design Schwäche:• Abschalten von server-side Validation

• Sicherheitsproblem !!!

• „Super“-Tags (type für Validator) • Alternativen:

• Apache MyFaces Tomahawk• Apache Trinidad

Page 36: Apache Shale

36

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – View Controller (I)• „Best practice“ => Eine Bean pro Seite:

• Ein „ViewController“• Häufig in JSF IDEs der Fall (JDeveloper / Creator)

• Erweitert die „page-orientierte“ Funktionsweise von JSF• init() • preprocess()• prerender()• destroy()• isPostBack()

Page 37: Apache Shale

37

Apache ShaleMatthias Weßendorf, Oracle Corp.

Shale – View Controller (II)• Convenience Implementierung

• AbstractViewController• Alle Methoden (leer) ausprogrammiert

• AbstractViewController extends AbstractFacesBean• Viele nützliche Hilfsmethoden

getBean(„#{myManagedBean}“);

Page 38: Apache Shale

38

Apache ShaleMatthias Weßendorf, Oracle Corp.

Zukunft• JSR 299 WebBeans

• Framework on top of JSF• Shale, wie Seam oder ADF ein Grund für „einheitliches“

Framework• Annotations für Rollen

• Google Guice (Java5 DI container)

• JavaServer Faces 2.0• Noch kein JSR!• Offene Diskussion in der „Community“• WebBeans Punkte stehen hier ebenfalls zur Diskussion ...

Page 39: Apache Shale

39

Apache ShaleMatthias Weßendorf, Oracle Corp.

Fragen ?

Folien:

http://slideshare.net/mwessendorf