Download - Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

Transcript
Page 1: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24

Shale: The Next Struts?Craig R. McClanahanSenior Staff Engineer

Sun Microsystems, Inc.

http://struts.apache.org/struts-shale/

Page 2: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 2

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 3: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 3

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 4: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 4

What Is Shale?

● An extension of JavaServer Faces technology● Originally proposed as “Struts 2.0”

● Accepted as a Struts sub-project● No direct connection with Struts Action

Framework● But provides corresponding functionality

● Not a repository of general purpose JavaServer Faces components

Page 5: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 5

Shale Tag Library

● <s:token>● <s:subview>● <s:commonsValidator>● <s:validatorScript>● <s:clay>

Page 6: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 6

Utilizes JSF Extension Points

● ShalePropertyResolver● ShaleVariableResolver● DialogNavigationHandler● ShaleViewHandler● TilesViewHandler

Page 7: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 7

DEMOShale at work

Page 8: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 8

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 9: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 9

Shale Validation Concepts

● Utilizes Jakarta Commons Validator● Same functionality used by Struts Action Framework

● Provides server-side and client side validation● Based on a single configured set of rules

● Implemented as a standard JSF Validator● <s:commonsValidator> tag in JSP pages

● Additional tag to incorporate generated JavaScript validation functions● <s:validatorScript> in JSP pages

Page 10: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 10

Using Shale Validation<h:form id=”form” onclick=”validateForm”> ... <h:inputText id=”creditCard”> <s:commonsValidator type=”required” arg=”#{messages['cc.required']}” client=”true”/> <s:commonsvalidator type=”creditCard” arg=”#{messages['cc.format']}” server=”true”/> </h:inputText> ... <s:validatorScript functionName=”validateForm”/> ...</h:form>

Page 11: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 11

DEMOShale validation

Page 12: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 12

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 13: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 13

Shale and Spring

● JavaServer Faces Managed Beans Facility provides basic “Dependency Injection” service:● Create beans on demand● Initialize properties from metadata● Store in specified scope

● Spring provides custom VariableResolver:● Is there a managed beans definition? Use it● Is there a Spring bean definition? Use it

● Evaluating value binding expressions can trigger Spring BeanFactory bean creation

Page 14: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 14

Shale and Tiles

● Enclose <tiles:insert> tags in subviews:<s:subview id=”loginPage”> <tiles:insert definition=”loginPage.jsp”/></s:subview>

● Specify Tiles as navigation destinations:<navigation-rule> <navigation-case> <from-outcome>todo-list</from-outcome> <to-view-id>todo-list.tile</to-view-id> </navigation-case></navigation-rule>

● Uses standalone Tiles not dependent on Struts

Page 15: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 15

DEMOSpring and Tiles

Page 16: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 16

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 17: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 17

Retro Views

● Use plain HTML to define your views:● Graphic artists can work with HTML● HTML elements reference components

● Define components in XML document● Tie HTML elements to component definitions with

jsfid attribute

Page 18: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 18

Two Usage Modes

● Preview:● Used by graphic artists and developers● http://localhost:8080/myapp/logon.html

● Runtime:● Used by developers and end users● http://localhost:8080/myapp/logon.faces

● Facility also supports reuse of component trees:● On-the-fly attribute substitution● Customization of value binding expressions

Page 19: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 19

DEMOTapestry-like Views

Page 20: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 20

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 21: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 21

Remoting

● Map incoming URL to processing logic:<catalog name=”remote”> <chain name=”/getCities.remote”> <command className=”com.mycompany.myapp.LoadState” state=”stateAbbreviation”/> <command className=”com.mycompany.myapp.GetCities”/> state=”stateAbbreviation”/> </chain></catalog>

● Construct response with Java code or JSP● Useful for server-side processing of Ajax requests

Page 22: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 22

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 23: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 23

View Controller

● JavaServer Faces developers are typically familiar with the standard request processing lifecycle of each request

● A simpler programming model would be if all coding were in response to events● Hollywood Principle: “don't call us, we'll call you”

● Implement ViewController interface to receive support for application lifecycle events● Uses only standard JavaServer Faces APIs● Portable to any runtime environment

Page 24: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 24

Application Lifecycle Events

● Application associates a backing bean with each JSP page corresponding to a view:● Backing bean can implement ViewController● (Optional) Components bound to concrete properties● Methods created for UI event handlers

● Shale does application lifecycle callbacks:● init() -- When a page bean is first created● preprocess() -- Before a form submit is processed● prerender() -- Before a view is rendered● destroy() -- After rendering, if init() was called

Page 25: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 25

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 26: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 26

Shale Dialog Concepts

● Based on design of Spring Web Flow:● Integrated with JavaServer Faces technology● Simpler, more intuitive API

● Models conversations as a State Diagram:● Action states● View states● Subdialog states

● Transitions between states based on logical outcomes returned by executing a state

● Supports “conversation scope” data storage

Page 27: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 27

Modelling Dialogs As State Diagrams

Page 28: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 28

Configuring Shale Dialogs<dialogs> <dialog name=”Create Account” start=”User Information”> <view name=”User Information”> <transition outcome=”next” target=”Phone Numbers”/> <transition outcome=”finish” target=”Create Account”/> </view> ... <action name=”Create Account” method=”#{account.create}”/> <end name=”Exit” viewId=”/login.jsp”/> </dialog></dialogs>

Page 29: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 29

Invoking Shale Dialogs

● Enter dialogs with a special logical outcome:● <h:commandButton action=”dialog:CreateAccount”/>

● When within a dialog:● Custom NavigationHandler manages navigations● Per-dialog state information maintained● Subdialogs cause stack push/pop of state information

● When not within a dialog:● Standard JavaServer Faces navigation processing

Page 30: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 30

DEMOShale Dialogs

Page 31: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 31

Agenda

What is Shale?ValidationSpring and Tiles IntegrationTapestry-like ViewsRemotingView ControllerDialogsSummary

Page 32: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 32

Current Status of Shale

● Test Build 1.0.0 available:● http://cvs.apache.org/dist/struts/shale/v1.0.0/

● Other resources:● http://struts.apache.org/struts-shale/● http://wiki.apache.org/struts/StrutsShale/● http://cvs.apache.org/builds/struts/nightly/struts-shale/

Page 33: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 33

Future Directions

● Shale Tiger Extensions:● Layer on top, using JavaSE 5 annotations● Annotations for managed bean definition● Annotations for view controller callbacks

● Improve Dialogs Functionality:● Multiple simultaneously executing dialogs● Start dialogs programmatically

● Improve Clay Functionality:● Load multiple templates from one resource● More implicit decorators

Page 34: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 34

Future Directions

● Improve View Controller Functionality:● More robust exception handling support● Optional phase listener callbacks

● Improve Remoting Functionality:● Support JSF ResponseWriter for creating response

● What else would you like to see?

Page 35: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24 | 35

Q&ACraig R. McClanahan

Page 36: Shale: The Next Struts? - The Apache Software Foundationpeople.apache.org/~craigmcc/apachecon-2005-shale.pdfOriginally proposed as “Struts 2.0” Accepted as a Struts sub-project

ApacheCon US 2005 | Session TU24

Shale: The Next Struts?Craig R. McClanahanSenior Staff Engineer

Sun Microsystems, Inc.http://struts.apache.org/struts-shale/