SlideShare une entreprise Scribd logo
1  sur  78
Télécharger pour lire hors ligne
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
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
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/
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.
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...
Why?
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
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
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Development
●   Client Side Bean Validation
●   Summary & Project Updates
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
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Development
●   Client Side Bean Validation
●   Summary & Project Updates
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
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" ... />
   <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>
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...
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...
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>
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>
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
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" />
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Development
●   Client Side Bean Validation
●   Summary & Project Updates
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]}" />
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”/>
What if you need to manipulate resources...
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
@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);
    }
    ....
Now Go Get It...



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



     ●   Assuming BradyResource is in
              ● Base package
              ● patriots.jar
Sending in the parameters...

@ResourceParameter
protected boolean longBall;




<h:outputScript value="#{resource['patriots:
                         BradyResource?longBall=true]}" />
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Development
●   Client Side Bean Validation
●   Summary & Project Updates
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...
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();
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
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>
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
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Development
●   Client Side Bean Validation
●   Summary & Project Updates
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*
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
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/>
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
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/>
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/>
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"/>

 ...
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"/>
  ...
Beyond JSF 2.0 with RichFaces

●   An Introduction
●   Built in Ajax
●   Built in Resource Handling
●   Component Development
●   Client Side Bean Validation
●   Summary & Project Updates
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....
Rich Components!
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
Beyond JSF 2.0 with Seam Faces
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowered Testability
●   Summary
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
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowered Testability
●   Summary
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
        {
           ...
        }
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."));
        }
    }
}
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.");
       }
    }
}
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>
Seam Faces - Converters & Validators

●   @Inject and @*Scoped support
●   Automatic type-conversion
●   Built-in support for i18n and l10n
●   Designed for re-use
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowered Testability
●   Summary
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?”
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?
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
                                       }
                                   }
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>
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
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowered Testability
●   Summary
Faces Messages in JSF 2.0




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




      @Inject
      Messages messages;


      messages.info("What a breath of {0} {1}!", "fresh", "air");
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
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowered Testability
●   Summary
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 ExternalContext
      @Inject NavigationHandler
      @Inject @Faces Locale
Beyond JSF 2.0 with Seam Faces

●   An Introduction
●   Conversion & Validation
●   Page Actions
●   Messages
●   Empowered Testability
●   Summary
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
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
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
Wrap up and Q&A
Going Above JSF 2.0 with RichFaces and Seam

Contenu connexe

Tendances

Kailas by Wadit in YAPC::Asia 2009
Kailas by Wadit in YAPC::Asia 2009Kailas by Wadit in YAPC::Asia 2009
Kailas by Wadit in YAPC::Asia 2009
Yusuke Wada
 
SPTechCon Dev Days - Third Party jQuery Libraries
SPTechCon Dev Days - Third Party jQuery LibrariesSPTechCon Dev Days - Third Party jQuery Libraries
SPTechCon Dev Days - Third Party jQuery Libraries
Mark Rackley
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014
Mark Rackley
 

Tendances (20)

Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
Oracle Application Express & jQuery Mobile - OGh Apex Dag 2012
 
Sq li
Sq liSq li
Sq li
 
Fundamentals of web_design_v2
Fundamentals of web_design_v2Fundamentals of web_design_v2
Fundamentals of web_design_v2
 
How Googlebot Renders (Roleplaying as Google's Web Rendering Service-- D&D st...
How Googlebot Renders (Roleplaying as Google's Web Rendering Service-- D&D st...How Googlebot Renders (Roleplaying as Google's Web Rendering Service-- D&D st...
How Googlebot Renders (Roleplaying as Google's Web Rendering Service-- D&D st...
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
 
SPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuideSPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuide
 
HTML5 workshop, part 1
HTML5 workshop, part 1HTML5 workshop, part 1
HTML5 workshop, part 1
 
SEO AJAX Crawlability in a Responsive Publisher World
SEO AJAX Crawlability in a Responsive Publisher WorldSEO AJAX Crawlability in a Responsive Publisher World
SEO AJAX Crawlability in a Responsive Publisher World
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
 
The SharePoint & jQuery Guide - Updated 1/14/14
The SharePoint & jQuery Guide - Updated 1/14/14The SharePoint & jQuery Guide - Updated 1/14/14
The SharePoint & jQuery Guide - Updated 1/14/14
 
AEM - Client Libraries
AEM - Client LibrariesAEM - Client Libraries
AEM - Client Libraries
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NET
 
Introduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint WorkshopIntroduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint Workshop
 
Kailas by Wadit in YAPC::Asia 2009
Kailas by Wadit in YAPC::Asia 2009Kailas by Wadit in YAPC::Asia 2009
Kailas by Wadit in YAPC::Asia 2009
 
Advanced Technical SEO - Index Bloat & Discovery: from Facets to Javascript F...
Advanced Technical SEO - Index Bloat & Discovery: from Facets to Javascript F...Advanced Technical SEO - Index Bloat & Discovery: from Facets to Javascript F...
Advanced Technical SEO - Index Bloat & Discovery: from Facets to Javascript F...
 
Modelling Web Performance Optimization - FFSUx
Modelling  Web Performance Optimization - FFSUxModelling  Web Performance Optimization - FFSUx
Modelling Web Performance Optimization - FFSUx
 
SPTechCon Dev Days - Third Party jQuery Libraries
SPTechCon Dev Days - Third Party jQuery LibrariesSPTechCon Dev Days - Third Party jQuery Libraries
SPTechCon Dev Days - Third Party jQuery Libraries
 
Rails MVC by Sergiy Koshovyi
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy Koshovyi
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014
 
Templates81 special document
Templates81 special documentTemplates81 special document
Templates81 special document
 

Similaire à Going Above JSF 2.0 with RichFaces and Seam

RichFaces: rich:* component library
RichFaces: rich:* component libraryRichFaces: rich:* component library
RichFaces: rich:* component library
Max Katz
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
Skills Matter
 

Similaire à Going Above JSF 2.0 with RichFaces and Seam (20)

A Peek At The Future: Going Beyond JavaServer Faces 2.0 With RichFaces 4
A Peek At The Future: Going Beyond JavaServer Faces 2.0 With RichFaces 4A Peek At The Future: Going Beyond JavaServer Faces 2.0 With RichFaces 4
A Peek At The Future: Going Beyond JavaServer Faces 2.0 With RichFaces 4
 
RichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsRichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF Applications
 
RichFaces 4 Component Deep Dive - JAX/JSFSummit
RichFaces 4 Component Deep Dive - JAX/JSFSummitRichFaces 4 Component Deep Dive - JAX/JSFSummit
RichFaces 4 Component Deep Dive - JAX/JSFSummit
 
What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSF
 
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJS
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJSAjax Applications with JSF 2 and New RichFaces 4 - TSSJS
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJS
 
RichFaces: rich:* component library
RichFaces: rich:* component libraryRichFaces: rich:* component library
RichFaces: rich:* component library
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
Hands On With Rich Faces 4 - JavaOne 2010
Hands On With Rich Faces 4 - JavaOne 2010Hands On With Rich Faces 4 - JavaOne 2010
Hands On With Rich Faces 4 - JavaOne 2010
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
RichFaces 4 webinar #2: RichFaces 3 toRichFaces 4
RichFaces 4 webinar #2: RichFaces 3 toRichFaces 4RichFaces 4 webinar #2: RichFaces 3 toRichFaces 4
RichFaces 4 webinar #2: RichFaces 3 toRichFaces 4
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Ajax Applications with JSF 2 and new RichFaces 4 - Herbstcampus
Ajax Applications with JSF 2 and new RichFaces 4 - HerbstcampusAjax Applications with JSF 2 and new RichFaces 4 - Herbstcampus
Ajax Applications with JSF 2 and new RichFaces 4 - Herbstcampus
 
Ajax Applications with JSF 2 and New RichFaces 4 - JAX/JSF Summit
Ajax Applications with JSF 2 and New RichFaces 4 - JAX/JSF SummitAjax Applications with JSF 2 and New RichFaces 4 - JAX/JSF Summit
Ajax Applications with JSF 2 and New RichFaces 4 - JAX/JSF Summit
 
JSF and Seam
JSF and SeamJSF and Seam
JSF and Seam
 
RichFaces 4 Webinar - New and Advanced Features
RichFaces 4 Webinar - New and Advanced FeaturesRichFaces 4 Webinar - New and Advanced Features
RichFaces 4 Webinar - New and Advanced Features
 
Jsf Ajax
Jsf AjaxJsf Ajax
Jsf Ajax
 
Javascript Bundling and modularization
Javascript Bundling and modularizationJavascript Bundling and modularization
Javascript Bundling and modularization
 
JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011JavaServer Faces 2.0 - JavaOne India 2011
JavaServer Faces 2.0 - JavaOne India 2011
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Going Above JSF 2.0 with RichFaces and Seam

  • 1.
  • 2. 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
  • 3. 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
  • 4. 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/
  • 5. 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.
  • 6. 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...
  • 8. 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
  • 9. 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
  • 10. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  • 11. 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
  • 12. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  • 13. 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
  • 14. RichFaces makes it better with.. ● a4j:region ● a4j:queue ● Partial updates for complex components
  • 15. 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>
  • 16. 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...
  • 17. 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...
  • 18. 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>
  • 19. 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>
  • 20. 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
  • 21. 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" />
  • 22. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  • 23. 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]}" />
  • 24. 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”/>
  • 25. What if you need to manipulate resources...
  • 26. 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
  • 27. @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); } ....
  • 28. Now Go Get It... <h:outputScript library="patriots" name="BradyResource"/> ● Assuming BradyResource is in ● Base package ● patriots.jar
  • 29. Sending in the parameters... @ResourceParameter protected boolean longBall; <h:outputScript value="#{resource['patriots: BradyResource?longBall=true]}" />
  • 30. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  • 31. 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...
  • 32. 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();
  • 33. 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
  • 34. 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>
  • 35. 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
  • 36. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  • 37. 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*
  • 38. 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
  • 39. 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/>
  • 40. 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
  • 41. 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/>
  • 42. 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/>
  • 43. 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"/> ...
  • 44. 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"/> ...
  • 45. Beyond JSF 2.0 with RichFaces ● An Introduction ● Built in Ajax ● Built in Resource Handling ● Component Development ● Client Side Bean Validation ● Summary & Project Updates
  • 46. 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....
  • 48. 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
  • 49. Beyond JSF 2.0 with Seam Faces
  • 50. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  • 51. 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
  • 52. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  • 53. 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 { ... }
  • 54. 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.")); } } }
  • 55. 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."); } } }
  • 56. 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>
  • 57. Seam Faces - Converters & Validators ● @Inject and @*Scoped support ● Automatic type-conversion ● Built-in support for i18n and l10n ● Designed for re-use
  • 58. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  • 59. 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?”
  • 60. 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?
  • 61. 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 } }
  • 62. 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>
  • 63. 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
  • 64. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  • 65. Faces Messages in JSF 2.0 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(SEVERITY_INFO, "Finally...", null));
  • 66. Faces Messages after a Redirect
  • 67. The Seam Faces Answer @Inject Messages messages; messages.info("What a breath of {0} {1}!", "fresh", "air");
  • 68. 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
  • 69. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  • 70. Testing JSF 2.0 FacesContext.getCurrentInstance();
  • 71. The Seam Faces Answer @Inject FacesContext context;
  • 72. Testing with Seam Faces ● Loose-coupling through @Inject ● Providers for: @Inject FacesContext @Inject ExternalContext @Inject NavigationHandler @Inject @Faces Locale
  • 73. Beyond JSF 2.0 with Seam Faces ● An Introduction ● Conversion & Validation ● Page Actions ● Messages ● Empowered Testability ● Summary
  • 74. 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
  • 75. 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
  • 76. 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
  • 77. Wrap up and Q&A