2008 - Shale and JSF Ken Sipe - Code Mentor
Jan 30, 2016
2008 - Shale and JSF
Ken Sipe - Code Mentor
2
Presentation Goal
Provide enough understanding for someone new to JSF and Shale to start coding…
3
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
4
About the Speaker
Sun Certified Java 2 Architect. Instructor for VisiBroker for Java, OOAD, Rational Rose,
and Java Development. Frequently speaks on the subject of distributed
computing programming, including CORBA and EJB architecture.
JBoss Certified Developer ;)
5
What is Shale?
JavaServer Faces JSF++ Extends JSF to add Functionality Added Components without the overhead of committee
Struts 2.0 Well it is the same guys who are involved A number of components carried over
Tiles FileUpload
Doesn’t work in the same MVC model of struts 1.x
http://struts .apache.org/shale http://wiki.apache.org/struts/StrutsShale
6
Shale Features
View Lifecycle Events Dialog
Web Flow
AJAX Support Validation
Commons Validator
Tiles Integration Spring Integration Tapestry-Like Views
7
Shale Tag Library
<s:token> Token pattern, used to prevent double posts
<s:subview> Used for Tiles... and dynamically added content
<s:commonsValidator> Used for commons validation
Client and Server
<s:validatorScript> Used with commons validation Client side
<s:clay> Tapestry Like
8
JSF Extension Points
ShalePropertyResolver Value binding expressions for JNDI
ShaleVariableResolver String Integration JNDI Lookups
ShaleViewHandler Lifecycle events for ViewControllers
TilesViewHandler Maps tile components
DialogNavigatioHandler The space between request and session
9
Shales Future
Ready a big question Craig says perhaps:
Struts 2.0 New Apache project Part of MyFaces Part of JSF 2.0
10
Shale Library References
Shale provides a number if jars for distribution: shale-core.jar shale-spring.jar shale-clay.jar shale-test.jar shale-tiles.jar
To use tiles you'll need tiles-core.jar
There are 2 tlds taglib.tld – contained in shale-cores.jar shale-clay.tld – contained in shale-clay.jar
11
Shale References
Shale makes significant use of jakarta commons commons-logging commons-validator commons-digester commons-beanutils commons-chain commons-collections
12
JBuilder Shale Configuration
Create a Library with Shale-core.jar Extract taglib.tld Configure a custom tag lib
13
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
14
JSF Events
JSF defines standard server side events and listener APIS: ActionEvent calls xxx_action() method and/or event listeners ValueChangeEvent calls xxx_valueChanged() method and/or
event listeners
Sufficient to deal with most low level UI components Insufficient to deal with application level events
15
Shale View Life-cycle Events
Shale extends server side event paradigm ViewController backing bean per page:
Standard “View Helper” design pattern Supports standard event handler methods init() preprocess() prerender() destroy()
Great for handling PostBacks in a slightly different way than the initial view.
16
Using ViewController
Implement the ViewController interface. org.apache.shale.view.ViewController
Provide a no-args public constructor. Declare your backing bean as a managed bean.
In nearly all circumstances, you will want the bean to be placed in request scope.
Provide public JavaBean properties that may be set to customize the functionality provided by this bean.
Ensure that the functionality of your backing bean is not dependent upon the order in which property setters are called.
Create event handlers for the lifecycle events of interest, plus standard JavaServer Faces event handlers for things like actions and value changes.
17
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
18
JSF Validation
JSF defines standard server validation capabilities which integrates well with JSF components
1..* validators per component are possible Model updates are only after validations occur.
19
Shale Validation
Jakarta Commons Validator Leverage the same rules created for struts 1.x applications Leverage same rules for other frameworks / applications
integrated with commons
Client-Side Validation Extends past JSF by providing validation at the client side
Tag Support <s:commonsValidator>
Client-side or Server-side or Both
<s:validatorScript> Generators client-side JavaScript
20
XML Configuration
Although there can be any number of files used for validation configuration, typically there is at least : Validation-rules.xml
Contains the xml defined rules Typically generic / Non application specific Provided with the struts download
21
Validation-rules.xml
<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.required">
<javascript><![CDATA[ …
22
Shale Validation Components<h:form onsubmit="return validateForm(this);">
… <h:inputText id="username" value="#{user.username}"> <s:commonsValidator type="required“ arg="User Name"
server="false“ client="true"/> </h:inputText> <h:message for="username"/>
<h:outputLabel for="password"> <h:outputText value="password"/> </h:outputLabel> <h:inputSecret id="password" value="#{user.password}"> <f:validateLength minimum="4" /> </h:inputSecret> <h:message for="password"/>… <s:validatorScript functionName="validateForm" /> </h:form>
DEMOShale Validation
24
Presentation Agenda
What is Shale? View LifeCycle Events Validation Spring Integration Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
25
Shale and Spring
DelegatingVariableResolver Access Spring beans with JSF expressions
#{user}
Zero-Configuration Just package shale-spring.jar and spring.jar in the lib of war applicationContext.xml
26
Presentation Agenda
What is Shale? View LifeCycle Events Validation Spring Integration Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
27
Tiles Shale Integration
Add to the lib directory of WAR shale-tiles.jar tiles-core.jar
28
Tiles and Shale
Can be leverage across all of Shale ViewIds of Dialogs Navigation Rule
<navigation-rule>
<navigation-case>
<from-outcome>*</from-outcome>
<to-view-id>login-page-tile</to-view-id>
</navigation-case>
</navigation-rule>
29
Shale Tiles Layout
<%@ taglib uri="http://jakarta.apache.org/tiles" prefix="tiles" %><%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<table class='<tiles:getAsString name="tileClass"/>'> <tr class='<tiles:getAsString name="rowClass"/>'> <td class='<tiles:getAsString name="dataClass"/>'> <f:subview id="tile"> <tiles:insert attribute='content' flush="false"/> </f:subview> </td> </tr></table>
30
Tiles.XML file
<!-- LOGIN PAGE TILE -->
<definition name="login-page-tile" extends="header-menu-content-tile">
<put name="header" value="header-tile"/><put name="menu" value="login-menu-tile"/><put name="content" value="/tiles/content/login/content.jsp"/>
</definition
31
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
32
Tapestry “Style”
Define a web page without any code Code is tied to page through html tag attributes.
jsfid
Web can be: Html JSP xml
33
Separation of Page Designer and Developer
Supports 2 Views Design Time (Web Developers)
http://localhost:8082/app/home.html
Run Time http://localhost:8082/app/home.faces
Designer Works with HTML
Developer JSP to include HTML XML to connect it all together
34
Configuration
clay-config.xml contains the jsfid replacement mappings
view-config.xml contains the component name references from clay-config.xml
shale-clay.jar
35
Login HTML
<span jsfid="usernamePrompt"> Username </span> <input jsfid="username" type="text" size="15"/> <span jsfid="usernameMessage"> username error message </span> <span jsfid="passwordPrompt"> Password </span> <input jsfid="password" type="password" size="8"/> <span jsfid="passwordMessage"> password error message </span> </td> <input jsfid="login" type="submit" value="Log on"/>
36
Login JSP
<f:view> <f:loadBundle basename="resources" var="msgs"/> <sh:clay id="loginTemplate" jsfid="/pages/clay-login.html" managedBeanName="loginPage"/></f:view>
37
JSP Page not required
WEB.XML configuration: <!-- Clay template suffix override, default is .clay --> <context-param> <param-name>clay-template-suffix</param-name>
<param-value>.html</param-value> </context-param>
38
Clay-Config.XML file <component jsfid="password" extends="inputSecret" id="password"> <attributes> <set name="size" value="3"/> <set name="value" value="#{userContext.password}"/> </attributes> </component>
<component jsfid="passwordMessage" extends="message" allowBody="false"> <attributes> <set name="for" value="password" /> </attributes> </component>
<component jsfid="login" extends="commandButton" id="login"> <attributes> <set name="action" value="#{managed-bean-name.submit}"/> <set name="value" value="Log In" /> </attributes>
39
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
40
AJAX – The New Buzz
Asynchronous JavaScript with XML Except it’s not always Asynchronous And It’s not always XML
Server submissions without a page post and refresh Out-side of Shale support I really like DWR
Direct Web Remoting http://getahead.ltd.uk/dwr/
41
AJAX / JSF Warning…
If you change the state of expected states values held by server… bad things happen Mainly the short-circuits the 2nd or 3rd phase of JSF (just for a
model update and redisplays the page.
42
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
43
Shale Dialogs
Modeled after Springs Web Flow Simplified Not complete duplication of Spring
Modeled as States and Transitions Get your STDs out
44
Dialog State Types
Action Represents a call to a public method, taking no parameters, and
returning a String that will be treated as the logical outcome
View Represents the rendering of a JavaServer Faces view
Subdialog Represents pushing the state of the current dialog onto a stack,
and starting a specified new dialog at its starting state
Exit Terminates the current dialog
45
Defining Dialogs - Dialog-config.xml
<dialog name="Create Account" start="User Information">
<!-- Transitions applicable to all states --> <transition outcome="cancel" target="Exit"/> <transition outcome="username" target="User Information"/> <transition outcome="phoneNumbers" target="Phone Numbers"/> <transition outcome="address" target="Address"/> <transition outcome="creditCard" target="Credit Card"/> <transition outcome="summary" target="Summary"/>
<!-- User Information -->
<view name="User Information" viewId="/pages/account.jsp"> <transition outcome="next" target="Phone Numbers"/> </view>
46
Defining Dialogs
<view name="Summary" viewId="/pages/account.jsp">
<transition outcome="previous" target="Credit Card"/> <transition outcome="finish" target="Create User"/>
</view>
<action name="Create User" method="#{accountPage.finish}"></action>
<!-- Exit --><end name="Exit"
viewId="/pages/login.jsp"/>
47
Working with Dialogs
Enter dialogs through JSF actions
<h:commandButton
value=‘register’
action=“dialog:Create Account” />
DialogNavigationHandler manages dialog flow From Dialog, navigate back to JSF
48
Multi-Dialog Configuration Files
<context-param> <param-name>
org.apache.shale.dialog.CONFIGURATION </param-name> <param-value>
/WEB-INF/account-dialogs.xml,/WEB-INF/user-dialogs.xml </param-value></context-param>
49
Presentation Agenda
What is Shale? View LifeCycle Events Validation Tiles Integration Clay – Tapestry-like Views AJAX Dialogs
50
Summary
Shale makes many common web development task easier.
Extension of JSF Not bound to JCP committee
Questions?
52
Thank You
2008
Web Application Development using Struts, Shale and JSF
Please fill out the speaker evaluation
You can contact me further at …[email protected]