What You Need To Build Cool Enterprise Applications With JSFPresentation Transcript
What You Need for BuildingCool Enterprise Applicationswith JSFMax KatzExadelOct. 4, 2011
>max@exadel.comMax Katz >@maxkatz >mkblog.exadel.comSenior Systems EngineerJSF, RichFaces, Java EE consulting,and trainingDeveloper Relations for Tiggr MobileApps Builder (http://gotiggr.com)
Exadel is a global software engineering companyFounded in 1998, headquarters in San Francisco Bay Area7 Development offices in Europe[Munich, Moscow, Ekaterinburg, Minsk, Homeyl, Kharkov, Donetsk] 400+ employees
The Plan Is Simple1) Ajax features in JSF 22) The new RichFaces 4 – orwhat you need to build coolenterprise applications withJSF
JavaServer Faces™ (JSF) is the standard component- based user interface (UI) framework for the Java EE (5 & 6) platform JSF 1.2 Java EE 5 JSF 2 Java EE 6
JSF 2 is a major upgrade over JSF 1.x Many features, ideas takenfrom projects such as Seam, RichFaces, and others
JSF 2 new features● Facelets ● New scopes● Composite ◦ Flash, View, components custom● Implicit ● Configuration navigation via annotations● GET ● Bean Validation support support ◦ h:link, h:button ● Basic Ajax● Resource loading
JSF 2 <f:ajax>● Very basic Ajax functionality● Greatly inspired by RichFaces 3 <a4j:support> tag● Ajax in JSF in 3 easy steps: 1. Sending an Ajax request 2.Partial view processing 3.Partial view rendering
Attribute ValueImportant Event on which to fire the<f:ajax> event Ajax requestattributes @all @this (default) @form execute @none ids EL @all @this @form render @none (default) ids EL
Thats good, but thats all you get.Where do you get rich components and more? A rich component framework isstill(?) needed to build real-world Ajax applications.
RichFaces 4 is a lightweight,open source framework for JSF 2
RichFaces 4 – rich JSF frameworkUI components a4j:* tag library (core) rich:* tag library (UI)Components JavaScript APISkinsClient-side validation (Bean Validationbased)CDK – Component Development Kit
100% built on top of JSF2,just extends functionality in JSF 2
JavaScript is now entirelybased on the popular jQuery library
RichFaces 4 is a lot faster, consistent,and optimized All components are reviewed for consistency, usability Redesigned following semantic HTML principles Server-side and client-side performance optimization Strict code clean-up and review
New client-side validationbased on Bean Validation (JSR 303)Quickly and easily validate input on the client
New, and easy to use CDK (Component Development Kit), allows quickly to build yourown custom rich components
Pick your server:Tomcat 6/7, Resin, JBoss AS 6/7, GlassFish 3.x, WebLogic[any server where JSF 2 application can be deployed]
Deploy and run in the cloud:Google App Engine AmazonEC2, CloudBees, OpenShift
Pick JSF implementations you like: Mojarra or MyFaces
Run in any browser
Pick your favorite tooling: JBoss Tools, IntelliJ, NetBeans
Easy to start. Zero-configuration, just drop RichFaces into the application
RichFaces versions Version JSF 1.1 JSF 1.2 JSF 2RichFaces 3.1.x •RichFaces 3.3.3* • •RichFaces 4 •* Note: RichFaces 3.3.3 has basic JSF 2 support
RichFaces history2005: started by Alexander Smirnov2005-2007: Developed by Exadel Ajax4jsf - open source, free RichFaces - commercial2007: JBoss takes over Exadel team continues to develop the framework, project is known as RichFaces
Lets see what coolcomponents, and features you get with RichFaces...
RichFaces <a4j:ajax> ● 100% based on standard <f:ajax> ● Just replace f: with a4j: and get exactly the same functionality ● But, you get extra features...<h:commandButton> <h:commandButton> <f:ajax execute="@form" render="output"/> <f:ajax execute="@form" render="output"/></h:commandButton> </h:commandButton><h:commandButton> <h:commandButton> <a4j:ajax execute="@form" render="output"/> <a4j:ajax execute="@form" render="output"/></h:commandButton> </h:commandButton>
<a4j:ajax> attributesFeature/Attribute Description JavaScript to execute before Ajaxonbegin request JavaScript to execute after responseonbeforedomupdate comes back but before DOM updateoncomplete JavaScript to execute after DOM update Allows to skip JSF phases whenbypassUpdates validatinglimitRender Turns off all auto-rendered panelsstatus Status to display during Ajax requestAjax queue Advanced RichFaces client queue
Components to send Ajaxrequest● <a4j:ajax>● <a4j:commandButton>● <a4j:commandLink>● <a4j:jsFunction>● <a4j:poll>● <a4j:push>
<a4j:commandButton/Link> –button and link with built-in Ajaxbehavior<a4j:commandButton value="Save" <a4j:commandButton value="Save" action="#{bean.action}" action="#{bean.action}" render="output" /> render="output" /><a4j:commandLink value="Save" <a4j:commandLink value="Save" action="#{bean.action}" action="#{bean.action}" render="output" /> render="output" />
When using standard JSF button:<h:form> <h:form> <h:inputText> <h:inputText> <h:selectOneMenu> Need to set <h:selectOneMenu> <h:commandButton> <h:commandButton> execute=”@form” <f:ajax execute="@form"/> <f:ajax execute="@form"/> (or execute=”id1 id2”) </h:commandButton> </h:commandButton><h:form> <h:form>When using RichFaces button:<h:form> <h:form> RichFaces default <h:inputText> <h:inputText> <h:selectOneMenu> value for <h:selectOneMenu> <a4j:commandButton/> <a4j:commandButton/> button/link<h:form> <h:form> execute=”@form”
If you had to pick just one Ajaxcontrol, you would want<a4j:jsFunction><h:commandButton action="#{bean.change}"> <h:commandButton action="#{bean.change}"> <a4j:ajax render="id"/> <a4j:ajax render="id"/></h:commandButton> </h:commandButton>Is the same as: <h:commandButton onclick="sendAjax();"/> <h:commandButton onclick="sendAjax();"/> <a4j:jsFunction name="sendAjax" <a4j:jsFunction name="sendAjax" action="#{bean.change}" render="id"/> action="#{bean.change}" render="id"/>
<a4j:push> ● Server-side events are pushed to client using Comet or WebSockets. ● Implemented using Atmosphere ● Providesexcellent integration with EE containers, and advanced messaging services<a4j:push address="topic@chat" <a4j:push address="topic@chat" ondataavailable="alert(event.rf.data)" /> ondataavailable="alert(event.rf.data)" />
render=”#{bean.renderList}”JSF RichFaces1) Ajax request sent 1) Ajax request sent2) Component ids to be 2) Component ids to rendered resolved be rendered3) Component ids are resolved rendered into the page 3) Component ids4) 2nd Ajax request is sent. are rendered In this request the components (resolved in step 2 are sent with request) will be rendered
JSF 2 queue● JSF2 has very basic queue functionality● Events are queued and fired one at a time● Only one request is processed on the server at a time
<a4j:queue> – “combining” eventsfrom the same component While a request is executing on the server, all requests from button A or button B will be combined (merged) if the last event in the queue is of the same type.<a4j:queue /> <a4j:queue />... ...<a4j:commandButton id="buttonA" value="Button A"/> <a4j:commandButton id="buttonA" value="Button A"/><a4j:commandButton id="buttonB" value="Button B"/> <a4j:commandButton id="buttonB" value="Button B"/>
<a4j:queue> – “combining” eventsfrom different components While a request is executing on the server, all requests from button A or button B will be combined (merged).<a4j:queue /> <a4j:queue /><a4j:commandButton id="buttonA" value="Button A"> <a4j:commandButton id="buttonA" value="Button A"> <a4j:attachdQueue requestGroupingId="ajaxGroup"/> <a4j:attachdQueue requestGroupingId="ajaxGroup"/></a4j:commandButton> </a4j:commandButton><a4j:commandButton id="buttonB" value="Button B"> <a4j:commandButton id="buttonB" value="Button B"> <a4j:attachdQueue requestGroupingId="ajaxGroup"/> <a4j:attachdQueue requestGroupingId="ajaxGroup"/></a4j:commandButton> </a4j:commandButton>
<a4j:queue> – setting request delayallows “waiting” for requests fromsame component in order to mergeevents<a4j:queue requestDelay="1000"/> <a4j:queue requestDelay="1000"/><a4j:commandButton id="buttonA" value="Button A"> <a4j:commandButton id="buttonA" value="Button A"> <a4j:attachdQueue requestDelay="2000"/> <a4j:attachdQueue requestDelay="2000"/></a4j:commandButton> </a4j:commandButton><a4j:commandButton id="buttonB" value="Button B"/> <a4j:commandButton id="buttonB" value="Button B"/>
<a4j:param> - like <f:param>, butsimpler as it also assigns the value toa bean property automatically<a4j:commandButton value="Save"> <a4j:commandButton value="Save"> <a4j:param value="1009" assignTo="#{bean.product}"/> <a4j:param value="1009" assignTo="#{bean.product}"/></a4j:commandButton> </a4j:commandButton>public class Bean { public class Bean { private String product; private String product; public void setProduct (String product) {...} public void setProduct (String product) {...}}}
Another great feature is that<a4j:param> value can contain anyJavaScript expression or JavaScriptfunction, when noEscape="true"<a4j:param name="width" <a4j:param name="width" value="(jQuery(window).width()/2)" value="(jQuery(window).width()/2)" assignTo="#{bean.screenWidth}" assignTo="#{bean.screenWidth}" noEscape="true" /> noEscape="true" />
RichFaces data iteration componentssupport partial updates render="@column" render="@header" render="@body" render="@footer" render="cellId"To render from outside the table:render="tableId@header"render="tableId@body"render="tableId@footer"
Deciding what rows/cell to update in run-timerender="tableId:rows(bean.rowsSet)"render="tableId:rows(bean.rowsSet):cellId"
New collapsible sub table component
<rich:dataTable> supports columnand row spanning
<rich:extendedDataTable> provideslazy loading, column resizing, reorderand more
More rich data iteration● a4j:repeat● rich:extendedDataTable● rich:collapsibleSubTable● rich:list ◦ list | ordered | definition● rich:dataGrid● rich:column ◦ Column and row spanning ◦ Filtering, sorting
rich:tree
Drag and drop
Many RichFaces componentsprovide client-side JavaScript API<rich:popupPanel> JavaScript APIMethod name Description Return the top co-ordinate for the position ofgetTop() the pop-up panel. Return the left co-ordinate for the position ofgetLeft() the pop-up panel. Move the pop-up panel to the co-ordinatesmoveTo(top,left) specified with the top and left parameters. Resize the pop-up panel to the size specifiedresize(width,height) with the width and height parameters.show() Show the pop-up panel.hide() Hide the pop-up panel.
RichFaces client functions Function Descriptionrich:client(id) Returns component client idrich:element(id) Returns DOM element Returns RichFaces client componentrich:component(id) instance to call JS API methodrich:isUserInRole(role) Returns if the user has specified role Returns component instance for givenrich:findComponent(id) short id
Standard Java EE security with#{rich:isUserInRole(role)} function<rich:panel header="Admin panel" <rich:panel header="Admin panel" rendered="#{rich:isUserInRole(admin)}"> rendered="#{rich:isUserInRole(admin)}"> Very sensitive information Very sensitive information</rich:panel> </rich:panel> <rich:panel header="User panel"> <rich:panel header="User panel"> General information General information</rich:panel> </rich:panel>● Calls facesContext.getExternalContext.getUserInRole(role)● Whats good is that security roles can be defined anywhere
Client-side validation based on Bean Validation (JSR 303) New in RichFaces 4
Bean Validation (JSR 303)JSF 2 has support for Bean Validation(validation done on server)Bean:public class Bean { public class Bean { @Pattern(regexp="...") @Pattern(regexp="...") private String email; private String email;}}JSF page:<h:inputText id="email" value="#{bean.email}"> <h:inputText id="email" value="#{bean.email}"> <a4j:ajax event="blur"/> <a4j:ajax event="blur"/></h:inputText> </h:inputText><rich:message for="email"/> <rich:message for="email"/>
Client-Validation Based on BeanValidationValidation is performed on the client. If no clientimplementation available, validation automatically fallsback to standard, server validationBean:public class Bean { public class Bean { @Pattern(regexp="...") @Pattern(regexp="...") private String email; private String email;}}JSF page:<h:inputText id="email" value="#{bean.email}"> <h:inputText id="email" value="#{bean.email}"> <rich:validator /> <rich:validator /></h:inputText> </h:inputText><rich:message for="email"/> <rich:message for="email"/>
Invoking <rich:jQuery> as a regularJavaScript function with mouse over<h:graphicImage width="100" value="/images/venice.png" <h:graphicImage width="100" value="/images/venice.png" onmouseover="larger(this, {})" onmouseover="larger(this, {})" onmouseout="normal(this, {})" /> onmouseout="normal(this, {})" /><rich:jQuery name="larger" <rich:jQuery name="larger" query="animate({width:241px})" /> query="animate({width:241px})" /><rich:jQuery name="normal" <rich:jQuery name="normal" query="animate({width:100px})"/> query="animate({width:100px})"/>
Skins
Skins● Lightweight extension on top of CSS● Change look and feel of all rich component with a few minor changes● Can be applied to standard JSF and HTML tags as well
Skinning standard JSF tags andHTML tagsApply to each control:<h:button style="background-color: <h:button style="background-color: #{richSkin.tableBackgroundColor}"/> #{richSkin.tableBackgroundColor}"/>
Skinning standard JSF tags andHTML tags automaticallyApply to all standard controls (JSF and HTML):<context-param> <context-param> <param-name> <param-name> org.richfaces.enableControlSkinning org.richfaces.enableControlSkinning </param-name> </param-name> <param-value>true</param-value> <param-value>true</param-value></context-param> </context-param>
Skinning standard JSF tags andHTML tags only when special CSSclass is applied to parent container<context-param> <context-param> <param-name> <param-name> org.richfaces.enableControlSkinningClasses org.richfaces.enableControlSkinningClasses </param-name> </param-name> <param-value>true</param-value> <param-value>true</param-value></context-param> </context-param><div class="rfs-ctn"> <div class="rfs-ctn"> <h:outputText /> <h:outputText /> <h:inputText /> <h:inputText /> <h:commandButton /> <h:commandButton /></div> </div>
Where can I try the new RichFaces 4?http://richfaces.org/showcase
RichFaces 4.1 (Late 2011)Mobile supportNew components: Pick list Ordering list Rich text editor
How can we help with RichFaces● Web development with RichFaces Training Days● Version 3 to 4 migration JSF 1.2, 2 1-2● Performance tune-up RichFaces 3, 4 1-2 JSF and RichFaces 2-3● Custom component RichFaces 3 to 4 1-2 development● On-site training
RichFacesRich, flexible, robust, andproven enterprise-levelframework to JSF 2
Tiggr is a Web-based mobile apps builder.Super fast, and easy to build mobile Web and native appsBuild your mobile app at http://gotiggr.com
Export or build the app as mobile Web or generate native app (for Android, iOS)
Thank you!How to get in touch with me:>max@exadel.com>@maxkatz>mkblog.exadel.comBuild your mobile app in thecloud: http://gotiggr.com