Apache Shale
-
Upload
mwessendorf -
Category
Technology
-
view
4.232 -
download
1
Embed Size (px)
description
Transcript of Apache Shale

Apache Shale
Was ist 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

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

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

5
Apache ShaleMatthias Weßendorf, Oracle Corp.
Shale – Bestandteile (I)
• Application Controller• Clay-Plugin• Dialog Manager• Remoting• Spring-Integration

6
Apache ShaleMatthias Weßendorf, Oracle Corp.
Shale – Bestandteile (II)
• Test-Framework• Tiles Integration• Tiger• Validator Support• View Contoller

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

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> ...

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; }}

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> ...

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

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

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>

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>

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>

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>...

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>

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

19
Apache ShaleMatthias Weßendorf, Oracle Corp.
Shale – Dialog Manager (II)

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

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>

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*

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;

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

25
Apache ShaleMatthias Weßendorf, Oracle Corp.
Shale – Remoting (II)

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 } );}

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(); }}

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)

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

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(); }

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

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

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

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>

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

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

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}“);

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 ...

39
Apache ShaleMatthias Weßendorf, Oracle Corp.
Fragen ?
Folien:
http://slideshare.net/mwessendorf