Going Above and Beyond JSF
        2 with RichFaces & Seam

Jay Balunas            Lincoln Baxter, III
Principal Software ...
Who's the big guy?

●   Jay Balunas
    ●   RichFaces Project Lead
    ●   JBoss Core Developer
    ●   http://in.relation...
Who's the tall guy?

  Lincoln Baxter, III                (@lincolnthree, blog)

   ●   Seam Faces Lead
   ●   Senior Soft...
Questions...



       Questions are welcome at anytime!*



 * As long as:
    “I’m not sure, but can find out”
    “Lets...
The Plan For Today
●   Quick review of JavaServer Faces
●   Review several features in more detail
     ●   For each featu...
Why?
What is JavaServer Faces (JSF)
●   Component based UI framework
●   Well defined request lifecycle
●   Standards based ( J...
What's so great about JSF 2.0
●   Annotations instead of       Integrated AJAX support
    XML
                           ...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Developm...
RichFaces Lighting Review
●   Ajax enabled JSF component library
     ●   100+ components...
●   Two tag libraries
     ● ...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Developm...
JSF 2.0 Built in Ajax via Tags
<h:inputText id="score_input" value="#{gameBean.score}" />
    <f:ajax event="keyup" execut...
RichFaces makes it better with..

● a4j:region
● a4j:queue


● Partial updates for complex

  components
RichFaces Ajax Region
<!-- Verify Address as part of a large form -->
<a4j:region>
   <h:inputText id="addr_01" ... />
   ...
JSF 2.0 Request Queue

●   Specification added Ajax requests
●   Requests need to be queued to preserve state
●   Good, bu...
RichFaces Request Queues
●   Adds a logical queue on top
     ●   Usability & customizations
●   Options
     ●   requestD...
RichFaces Request Queues
<h:form id="form">
  <!-- Queue applied to whole form -->
  <a4j:queue requestDelay="500"/>

  <h...
RichFaces Request Queues

<!-- Player lookups are more costly, send less often -->
<a4j:queue name="player_queue" requestD...
Partial Updates for Component Parts

●   JSF 2.0 limits updates
     ●   Key words ( @form, @this, etc.. )
     ●   specif...
Partial Updates for Iteration Components

<!-- Will render only the body of the table -->
<a4j:ajax render="table_id:@body...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Developm...
JSF 2.0 Loading Images

<!-- Loads from <web-root>/resources -->
<h:graphicImage name="fenway.jpeg />

<!-- Loads from sta...
JSF 2.0 Loading JavaScript & CSS
●   Two new resource components


<!-- Loads where you put it -->
<h:outputScript name=”p...
What if you need to manipulate resources...
Dynamic Resources in RichFaces

●   Extends JSF 2.0 resource handler
●   Used by RichFaces internally
     ●   Skinning
  ...
@DynamicResource
public class BradyResource implements UserResource{
    protected byte[] mossObject;
    protected byte[]...
Now Go Get It...



<h:outputScript library="patriots" name="BradyResource"/>



     ●   Assuming BradyResource is in
   ...
Sending in the parameters...

@ResourceParameter
protected boolean longBall;




<h:outputScript value="#{resource['patrio...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Developm...
JSF 2.0 Component Development

●   New annotations
     ●   @FacesComponent, @FacesRenderer
●   Create:
     ●   Tag handl...
JSF 2 Component Development
  ResponseWriter writer = context.getResponseWriter();
  assert(writer != null);
  String form...
RichFaces Component Development Kit

●   Does much of the leg work for you!
●   In many situations you only need:
     ●  ...
RichFaces Renderer Template
<cc:implementation>
  <c:choose>
    <c:when test="#{not component.attributes['disabled']}">
 ...
RichFaces Component Development
●   Abstract component class
     ●   Only implement component functionality
     ●   CDK ...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Developm...
What is Bean Validation

●   Bean Validation JSR-303
     ●   Part of Java EE6
●   Generic, tier independent constraints
●...
Bean Validation Sample
public class User {
   @NotEmpty @Size(max=100)
   private String loginname;

   @NotEmpty
   @Patt...
JSF 2.0 Bean Validation Integration
    Login:
    <h:inputText id="login" value="#{user.login}"/>
    <h:message for="log...
RichFaces Bean Validation
●   Takes it to the Client
     ●   Ajax fallback options
●   JavaScript:
     ●   Validation, C...
RichFaces Client Validation - Inputs
Login:
<h:inputText id="login" value="#{user.login}">
    <rich:clientValidator event...
RichFaces Client Validation - Forms
<h:form id="register">
   <!-- This will verify when form submitted
        & default ...
RichFaces Client Validation

<h:form id="register">
  <rich:clientValidator/>

 Login:
 <h:inputText id="login" value="#{u...
RichFaces Client Validation

<h:form id="register">
  <rich:clientValidator/>
  ...
  Name:
  <h:inputText id="name" value...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Developm...
JSF 2.0 + RichFaces == Rich & Easy JSF
●   JSF 2.0 added a lot
     ●   Left the door open for inovation!!
●   RichFaces i...
Rich Components!
RichFaces Project Updates
●   4.0 Release Plans
     ●   Alpha2 just released
     ●   Milestone releases every month
●   ...
Beyond JSF 2.0 with Seam Faces
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowere...
Seam Faces – An Introduction

●   Portable extension for JavaServer Faces & CDI
●   One of many independent modules in Sea...
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowere...
Conversion/Validation in JSF 2.0


●   No more XML
         @FacesValidator("addressValidator")
         public class Addr...
Cross-field Validation in JSF 2.0

@FacesValidator("badAddressValidator")
public class BadAddressValidator implements Vali...
The Seam Faces Answer

@FacesValidator("addressValidator")
public class AddressValidator implements Validator
{
   @Inject...
The Seam Faces Answer


<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmln...
Seam Faces - Converters & Validators

●   @Inject and @*Scoped support
●   Automatic type-conversion
●   Built-in support ...
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowere...
Page actions with GET in JSF 2.0


     <f:metadata>
          <f:viewParam name="id" value="#{blogManager.entryId}" />
  ...
Page actions with GET in JSF 2.0

●   But can you navigate?
●   Can you execute in a different phase, conditionally?
●   C...
The Seam Faces Answer

    <f:metadata>
         <f:viewParam name="id" value="#{blogManager.entryId}" />

         <s:vie...
The Seam Faces Answer



       <navigation-rule>
          <from-view-id>/entry.xhtml</from-view-id>
          <navigatio...
Seam Faces – Page actions with GET

●   Integrated with Faces Navigation
●   Invoke at specific phases of JSF lifecycle
● ...
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowere...
Faces Messages in JSF 2.0




FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(SEVERITY_INFO, "Finally....
Faces Messages after a Redirect
The Seam Faces Answer




      @Inject
      Messages messages;


      messages.info("What a breath of {0} {1}!", "fresh...
The Seam Faces Answer

●   A true @FlashScoped context
●   Lives from “now” until Render Response (even through
    HTTP r...
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowere...
Testing JSF 2.0




             FacesContext.getCurrentInstance();
The Seam Faces Answer




              @Inject
              FacesContext context;
Testing with Seam Faces

●   Loose-coupling through @Inject
●   Providers for:
      @Inject FacesContext
      @Inject Ex...
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowere...
Summary of JSF 2.0 with Seam Faces

●   Conversion & Validation
     ●   @Inject and @*Scoped support
     ●   Cross-field...
Seam Faces Plan

●   Release Plans:
     ●   Working on 3.0.0.Alpha4
     ●   Beta by late-July
     ●   Try it now!
●   G...
Whats bugging you with JSF 2.0

●   What do you wish were added to spec?
●   What is still missing?
●   We are maintaining...
Wrap up and Q&A
Going Above JSF 2.0 with RichFaces and Seam
Going Above JSF 2.0 with RichFaces and Seam
Upcoming SlideShare
Loading in...5
×

Going Above JSF 2.0 with RichFaces and Seam

4,256

Published on

In this session, Jay Balunas and Lincoln Baxter, III will provide in-depth coverage of several of the new JSF 2.0 features, focusing on the sufficiency and shortcomings of each feature. They will also review how RichFaces 4 and Seam 3 are enhancing JSF to solve these shortcomings by prototyping functionality for the future of JSF.

The JSF 2.0 specification (JSR-314) addresses a substantial number of long standing pain points that JSF users have come to accept as a hard-knock life. At last, JSF is a true contender amongst Web frameworks. However, JSF 2.0 is not the end of the story as, thankfully, the expert group has once again left the door open for projects like RichFaces and Seam to extend, prototype, and improve the specification. RichFaces leads the industry with Ajax support for JSF1.2, played a significant role in the development of JSF 2.0, and continues to lead and prototype the future of the JSF standard for the RIA ecosystem; Seam provides leading support for the Conversation Scope, Flash Scope, Internationalized Messages, Managed Transactions, and Conversion/Validation - including cross-field validation.

While this session effectively provides an overview of the JSF 2.0 specification, the underlying goal of this session is to serve as an outreach to identify outstanding recommendations for making the framework more pleasant and productive to use. In addition, this session will illustrate how members of the JSF community can get a sneak peek into the future by using the RichFaces and/or Seam projects. Whether you are a new JSF/RichFaces/Seam user who wants to find out more about the latest developments in the specification, or an old hat with an issue or two on your mind, this session has something to offer you . Attendees are encouraged to bring their own concerns and suggestions to this session.

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,256
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
144
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

Going Above JSF 2.0 with RichFaces and Seam

  1. 1. Going Above and Beyond JSF 2 with RichFaces & Seam Jay Balunas Lincoln Baxter, III Principal Software Senior Software Engineer Engineer JBoss, By Red Hat Inc
  2. 2. Who's the big guy? ● Jay Balunas ● RichFaces Project Lead ● JBoss Core Developer ● http://in.relation.to/Bloggers/Jay ● http://twitter.com/tech4j ● jbalunas@jboss.org Co-author of RichFaces Dzone RefCard
  3. 3. Who's the tall guy? Lincoln Baxter, III (@lincolnthree, blog) ● Seam Faces Lead ● Senior Software Engineer, JBoss ● JavaServer Faces EG Member ● Creator of PrettyFaces URL-rewriting extension for JSF & Java EE ● Co-founder of OcpSoft ● http://ocpsoft.com/
  4. 4. Questions... Questions are welcome at anytime!* * As long as: “I’m not sure, but can find out” “Lets discuss after the talk” “I can point you in the right direction, but....” are acceptable answers.
  5. 5. The Plan For Today ● Quick review of JavaServer Faces ● Review several features in more detail ● For each feature ● Where JSF 2.0 improved on JSF 1.X ● Where the new feature may fall short ● Show how RichFaces & Seam improve it ● Wrap up, and questions...
  6. 6. Why?
  7. 7. What is JavaServer Faces (JSF) ● Component based UI framework ● Well defined request lifecycle ● Standards based ( JCP ) ● Many extension points ● Component libraries ● Phase listeners ● View handlers ● Renderers
  8. 8. What's so great about JSF 2.0 ● Annotations instead of Integrated AJAX support XML New event systems ● Facelets integration Bean validation ● Composite components & templates Exception handling ● JSP deprecated Navigation updates ● View parameters Behaviors framework ● Built in resource handling EL access to component values ● Project stages
  9. 9. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  10. 10. RichFaces Lighting Review ● Ajax enabled JSF component library ● 100+ components... ● Two tag libraries ● a4j : Framework level ajax support ● rich : Component level ajax support ● Skinning & Themes ● Component Development Kit (CDK) ● Dynamic Resource Framework
  11. 11. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  12. 12. JSF 2.0 Built in Ajax via Tags <h:inputText id="score_input" value="#{gameBean.score}" /> <f:ajax event="keyup" execute=”@this” render="@form" /> </h:inputText> <h:outputText id="score_output" value="#{gameBean.score}" /> Execute [@this] Key words id's to process on server @all @none Render [@none] @this id's to re-render to client @form
  13. 13. RichFaces makes it better with.. ● a4j:region ● a4j:queue ● Partial updates for complex components
  14. 14. RichFaces Ajax Region <!-- Verify Address as part of a large form --> <a4j:region> <h:inputText id="addr_01" ... /> <h:inputText id="addr_02" ... /> <h:inputText id="city" ... /> <h:inputText id="state" ... /> <h:inputText id="zip" ... /> ... <h:commandLink action="#{registerBean.verifyAddress}" > <a4j:ajax/> <!-- <f:ajax execute="@this addr_01 addr_02 city state zip"/> --> </h:commandLink> </a4j:region>
  15. 15. JSF 2.0 Request Queue ● Specification added Ajax requests ● Requests need to be queued to preserve state ● Good, but limited ● Very few options ● No client side api ● Can lead to traffic jams...
  16. 16. RichFaces Request Queues ● Adds a logical queue on top ● Usability & customizations ● Options ● requestDelay & request grouping ● IgnoreDupResponses (in development) ● Client side API ● <queueObj>.getSize() ● <queueObj>.isEmpty() ● <queueObj>.set/getQueueOptions() ● etc...
  17. 17. RichFaces Request Queues <h:form id="form"> <!-- Queue applied to whole form --> <a4j:queue requestDelay="500"/> <h:inputText id="team1" value="#{gameBean.team1}" /> <a4j:ajax event="keyup" .../>   </h:inputText> <h:inputText id="team2" value="#{gameBean.team2}" /> <a4j:ajax event="keyup" .../>   </h:inputText> ... </h:form>
  18. 18. RichFaces Request Queues <!-- Player lookups are more costly, send less often --> <a4j:queue name="player_queue" requestDelay="1000"/> ... <h:inputText id="player" value="#{gameBean.cur_player}" /> <a4j:ajax event="keyup" ...> <!-- Requests from here will use player_queue --> <a4j:attachQueue name="player_queue"/> </a4j:ajax> </h:inputText>
  19. 19. Partial Updates for Component Parts ● JSF 2.0 limits updates ● Key words ( @form, @this, etc.. ) ● specific component ids ● RichFaces adds updates within complex components ● Table supports: @body, @header, @footer ● @row & @cell still in development ● Support for collection of rows ● Refer to specific rows for render ● In development ● Others, like tabPanel:@header in future
  20. 20. Partial Updates for Iteration Components <!-- Will render only the body of the table --> <a4j:ajax render="table_id:@body"/> <!-- Will render only the current row --> <rich:column> <a4j:commandButton render="@row"/> </rich:column> <!-- Will render the collection of rows/cells --> <a4j:commandButton render= "#{rich:rowKeys(someCollection, 'tableId')}:cellId" />
  21. 21. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  22. 22. JSF 2.0 Loading Images <!-- Loads from <web-root>/resources --> <h:graphicImage name="fenway.jpeg /> <!-- Loads from stadiums.jar/META-INF/resources --> <h:graphicImage name="foxborough.jpeg" library="stadiums"/> <!-- EL notation --> <h:graphicImage value="#{resource['stadiums:foxborough.jpeg]}" />
  23. 23. JSF 2.0 Loading JavaScript & CSS ● Two new resource components <!-- Loads where you put it --> <h:outputScript name=”patriots.js”/> <!-- Loads in the <h:head> --> <h:outputScript name=”patriots.js” target=”head”/> <!-- CSS always loads in <h:head> --> <h:outputStylesheet name=”celtics.css” library=”garden”/>
  24. 24. What if you need to manipulate resources...
  25. 25. Dynamic Resources in RichFaces ● Extends JSF 2.0 resource handler ● Used by RichFaces internally ● Skinning ● CSS with embedded EL ● Java2D ● Make your own!! ● Custom icons with state info ● Dynamic CSS & JS
  26. 26. @DynamicResource public class BradyResource implements UserResource{ protected byte[] mossObject; protected byte[] welkerObject; protected boolean longBall; public InputStream getInputStream() throws IOException { byte[] data; if (longBall) { data = mossObject; } else{ data = welkerObject; } return new ByteArrayInputStream(data); } ....
  27. 27. Now Go Get It... <h:outputScript library="patriots" name="BradyResource"/> ● Assuming BradyResource is in ● Base package ● patriots.jar
  28. 28. Sending in the parameters... @ResourceParameter protected boolean longBall; <h:outputScript value="#{resource['patriots: BradyResource?longBall=true]}" />
  29. 29. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  30. 30. JSF 2.0 Component Development ● New annotations ● @FacesComponent, @FacesRenderer ● Create: ● Tag handlers and tag lib files ● Faces-config.xml file ● Extend UIComponentBase class ● Implement the decode/encode*() methods ● Component functionality classe ● Maintain it all...
  31. 31. JSF 2 Component Development ResponseWriter writer = context.getResponseWriter(); assert(writer != null); String formClientId = RenderKitUtils.getFormClientId(command, context); if (formClientId == null) { return; } Just part of //make link act as if it's a button using javascript CommandLinkRenderer.java writer.startElement("a", command); writeIdAttributeIfNecessary(context, writer, command); writer.writeAttribute("href", "#", "href"); RenderKitUtils.renderPassThruAttributes(context,writer,command, ATTRIBUTES, getNonOnClickBehaviors(command)); RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, command); String target = (String) command.getAttributes().get("target"); if (target != null) { target = target.trim(); } else { target = ""; } Collection<ClientBehaviorContext.Parameter> params = getBehaviorParameters(command); RenderKitUtils.renderOnclick(context, command, params, target, true); writeCommonLinkAttributes(writer, command); // render the current value as link text. writeValue(command, writer); writer.flush();
  32. 32. RichFaces Component Development Kit ● Does much of the leg work for you! ● In many situations you only need: ● Abstract component class ● Renderer template in xml/xhtml ● Integrates into your build ● Maven-plugin ● IDE support ● standard xml files & schema
  33. 33. RichFaces Renderer Template <cc:implementation> <c:choose> <c:when test="#{not component.attributes['disabled']}"> <a id="#{clientId}" name="#{clientId}" cdk:passThroughWithExclusions="value" onclick="#{this.getOnClick(facesContext, component)}" href="#"> #{component.attributes['value']} <cdk:call expression="renderChildren(facesContext, component)" /> </a> </c:when> <c:otherwise> <span id="#{clientId}" cdk:passThroughWithExclusions="value"> #{component.attributes['value']} <cdk:call expression="renderChildren(facesContext, component)" /> </span> </c:otherwise> </c:choose> </cc:implementation>
  34. 34. RichFaces Component Development ● Abstract component class ● Only implement component functionality ● CDK will extend it based on: ● Template ● Config options ● CDK will compile template for renderer ● Including concrete component class ● Getters/setters, etc.. ● Tag handlers, tab lib, and faces-config files
  35. 35. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  36. 36. What is Bean Validation ● Bean Validation JSR-303 ● Part of Java EE6 ● Generic, tier independent constraints ● Custom, and composition constraints possible ● Constraint groups, and object graph validation too ● Message localization ● Define constraints once, apply everywhere*
  37. 37. Bean Validation Sample public class User { @NotEmpty @Size(max=100) private String loginname; @NotEmpty @Pattern(regexp = "[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0- 9]+") private String email; @NotEmpty @ValidTeam private String team; } Custom constraint
  38. 38. JSF 2.0 Bean Validation Integration Login: <h:inputText id="login" value="#{user.login}"/> <h:message for="login"/> <br/> Email: <h:inputText id="email" value="#{user.email}"/> <h:message for="email"/> <br/> Team: <h:inputText id="team" value="#{user.team}"> <f:validateBean disabled="true"/> </h:inputText> <h:message for="team"/> <br/>
  39. 39. RichFaces Bean Validation ● Takes it to the Client ● Ajax fallback options ● JavaScript: ● Validation, Converters, Messages ● Can be applied to: ● Inputs, Forms, View, or Application wide ● Develop you own validators ● Client/server JS mapping
  40. 40. RichFaces Client Validation - Inputs Login: <h:inputText id="login" value="#{user.login}"> <rich:clientValidator event="keyup"/> </h:inputText> <h:message for="login"/> <br/> Email: <h:inputText id="email" value="#{user.email}"> <rich:clientValidator event="keyup"/> </h:inputText> <h:message for="email"/> <br/>
  41. 41. RichFaces Client Validation - Forms <h:form id="register"> <!-- This will verify when form submitted & default JSF event of form children --> <rich:clientValidator/> Login: <h:inputText id="login" value="#{user.login}"/> <h:message for="login"/> <br/> Email: <h:inputText id="email" value="#{user.email}"/> <h:message for="email"/> <br/>
  42. 42. RichFaces Client Validation <h:form id="register"> <rich:clientValidator/> Login: <h:inputText id="login" value="#{user.login}"> <!-- would trigger validation pre-request on key up--> <rich:clientValidator event="keyup"/> <f:ajax event="keyup" listener="#{bean.loginTaken}"/> </h:inputText> <h:message for="login"/> ...
  43. 43. RichFaces Client Validation <h:form id="register"> <rich:clientValidator/> ... Name: <h:inputText id="name" value="#{user.name}"> <!-- Disable client validation --> <rich:clientValidator disabled="true"/> </h:inputText> <h:message for="name"/> ...
  44. 44. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  45. 45. JSF 2.0 + RichFaces == Rich & Easy JSF ● JSF 2.0 added a lot ● Left the door open for inovation!! ● RichFaces is prototyping the future of the spec ● You get to use it first with RichFaces ● Improvements ● Usability, and performance ● Dynamic resources ● Component development ● Client side bean validation ● & more....
  46. 46. Rich Components!
  47. 47. RichFaces Project Updates ● 4.0 Release Plans ● Alpha2 just released ● Milestone releases every month ● Lots of ways to get involved and stay informed ● Twitter ( http://twitter/com/richfaces ) ● Forums ● http://community.jboss.org/en/richfaces/dev ● Development projects & tasks ● https://jira.jboss.org/browse/RF ● Team Meetings, and IRC ● #richfaces @ irc.freenode.net
  48. 48. Beyond JSF 2.0 with Seam Faces
  49. 49. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  50. 50. Seam Faces – An Introduction ● Portable extension for JavaServer Faces & CDI ● One of many independent modules in Seam 3 ● Plug & Play ● The icing on your cake
  51. 51. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  52. 52. Conversion/Validation in JSF 2.0 ● No more XML @FacesValidator("addressValidator") public class AddressValidator implements Validator { ... } ● Automatic conversion @FacesConverter(forClass = ZipCode.class) public class ZipCodeConverter implements Converter { ... }
  53. 53. Cross-field Validation in JSF 2.0 @FacesValidator("badAddressValidator") public class BadAddressValidator implements Validator { Directory directory = new DatabaseAddressDirectory("host", 3036, "schema", "username", "password"); @Override public void validate(FacesContext context, UIComponent c, Object val) throws ValidatorException { String city = context.getExternalContext().getRequestParameterMap().get("form:table:city"); String state = context.getExternalContext().getRequestParameterMap().get("form:table:state"); String zipValue = context.getExternalContext().getRequestParameterMap().get("form:table:zip"); ZipCode zip = new ZipCode(Integer.valueOf(zipValue)); if (directory.exists(city, state, zip)) { throw new ValidatorException(new FacesMessage("Invalid address. Please try again.")); } } }
  54. 54. The Seam Faces Answer @FacesValidator("addressValidator") public class AddressValidator implements Validator { @Inject Directory directory; @Inject @InputField String city; @Inject @InputField String state; @Inject @InputField ZipCode zip; public void validate(FacesContext context, UIComponent c, Object val) throws ValidatorException { if (!directory.exists(city, state, zip)) { throw new ValidatorException("Invalid address. Please try again."); } } }
  55. 55. The Seam Faces Answer <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:s="http://jboss.org/seam/faces"> <h:form id="form"> City: <h:inputText id="city" value="#{bean.city}" /> <br/> State: <h:inputText id="state" value="#{bean.state}" /> <br/> Zip: <h:inputText id="zipCode" value="#{bean.zip}" /> <br/> <h:commandButton id="submit" value="Submit" action="#{bean.submit}" /> <s:validateForm validatorId="addressValidator" fields="zip=zipCode" /> </h:form> </html>
  56. 56. Seam Faces - Converters & Validators ● @Inject and @*Scoped support ● Automatic type-conversion ● Built-in support for i18n and l10n ● Designed for re-use
  57. 57. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  58. 58. Page actions with GET in JSF 2.0 <f:metadata> <f:viewParam name="id" value="#{blogManager.entryId}" /> <f:event name="preRenderView" listener="#{blogManager.loadEntry}" /> </f:metadata> @ManagedBean @RequestScoped public class BlogManager { public void listener(ComponentSystemEvent event) throws AbortProcessingException { // do something here } } “You can do that?”
  59. 59. Page actions with GET in JSF 2.0 ● But can you navigate? ● Can you execute in a different phase, conditionally? ● Can you enable/disable execution on a POST?
  60. 60. The Seam Faces Answer <f:metadata> <f:viewParam name="id" value="#{blogManager.entryId}" /> <s:viewAction action="#{blogManager.loadEntry}" phase="APPLY_REQUEST_VALUES" if="#{conversation.transient}" onPostback="true" />  </f:metadata> @Named public class BlogManager { private String entryId; private Entry entry; public void loadEntry() { // attempt to load the entry } }
  61. 61. The Seam Faces Answer <navigation-rule> <from-view-id>/entry.xhtml</from-view-id> <navigation-case> <from-action>#{blogManager.loadEntry}</from-action> <if>#{empty blogManager.entry}</if> <to-view-id>/home.xhtml</to-view-id> <redirect/> </navigation-case> </navigation-rule>
  62. 62. Seam Faces – Page actions with GET ● Integrated with Faces Navigation ● Invoke at specific phases of JSF lifecycle ● Conditional invocation on GET / POST ● Conditional invocation via EL
  63. 63. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  64. 64. Faces Messages in JSF 2.0 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(SEVERITY_INFO, "Finally...", null));
  65. 65. Faces Messages after a Redirect
  66. 66. The Seam Faces Answer @Inject Messages messages; messages.info("What a breath of {0} {1}!", "fresh", "air");
  67. 67. The Seam Faces Answer ● A true @FlashScoped context ● Lives from “now” until Render Response (even through HTTP redirects and navigation) ● Messages automatically saved in flash scope ● Fluent, testable API from Seam International Module ● Supports i18n and resource_bundle.properties
  68. 68. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  69. 69. Testing JSF 2.0 FacesContext.getCurrentInstance();
  70. 70. The Seam Faces Answer @Inject FacesContext context;
  71. 71. Testing with Seam Faces ● Loose-coupling through @Inject ● Providers for: @Inject FacesContext @Inject ExternalContext @Inject NavigationHandler @Inject @Faces Locale
  72. 72. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  73. 73. Summary of JSF 2.0 with Seam Faces ● Conversion & Validation ● @Inject and @*Scoped support ● Cross-field validation ● Page Actions ● With integrated navigation ● Messages ● Translated, Survive redirects via @FlashScoped ● Empowered Testability ● Avoid statics, use @Inject
  74. 74. Seam Faces Plan ● Release Plans: ● Working on 3.0.0.Alpha4 ● Beta by late-July ● Try it now! ● Get involved in the Project: http://seamframework.org/Seam3/FacesModule ● Submit feature requests (and bugs) to Seam Faces: https://jira.jboss.org/browse/SEAMFACES
  75. 75. Whats bugging you with JSF 2.0 ● What do you wish were added to spec? ● What is still missing? ● We are maintaining a list of updates for the next rev http://seamframework.org/Documentation/JSF21 ● Both Seam, and RichFaces topics
  76. 76. Wrap up and Q&A
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×