SlideShare a Scribd company logo
MyFaces CODI Scopes
Use the right scopes for your CDI beans
Agenda


•   The History
•   CODI in a Nutshell
•   CODI Setup
•   CODI Scopes in Action
•   Coding
•   CODI Conversation - Insights
•   Your Use-Cases
THE HISTORY
Scopes of the Servlet Spec

                         Application



                        Session




                  Custom Scopes




              Request
CODI Scope Overview

                           Application



                        Session



                      Window



               Conversation



             View-Access



            Request
Why custom Scopes?


• Request scope too short for most UI-Use-Cases
• Session scope
   – Too long
   – No support for multi-window applications
• Different (conversation) concepts available
   – MyFaces Orchestra
   – CDI Conversation Scope
   – MyFaces CODI Scopes
       • Conversation Scope
       • View-Access Scope
       • Window Scope
MyFaces Orchestra


•   CODI is NOT Orchestra.NEXT
•   Orchestra is for Spring (only)
•   CODI is for CDI (only)
•   Orchestra introduced great concepts!
     CODI was planned as "type-safe Orchestra" for CDI
    Now it’s way more (in most areas) but
    without Persistence-Management!
What‘s about @ConversationScoped of CDI?


• Completely broken for several use-cases!
• More like inflexible sessions per window
• Some of the disadvantages
   –   Overhead e.g. with failed conversion/validation
   –   Lazy termination (after the rendering process)
   –   Restarting conversations during a request isn’t possible
   –   End the whole conversation or nothing
   –   An explicit start is required
   –   Manual check if conversation has been started
• Test them with your use-cases!
   use them or forget them 
MyFaces CODI - Overview


• MyFaces Extensions CDI aka MyFaces CODI is a
  portable CDI extension which can be used with
  Apache OpenWebBeans, JBoss Weld,… and
  in combination with other portable CDI extensions
• CODI-Core is required in any case
• Modules
   –   JSF Module (for 1.2 and 2.0 and 2.1)
   –   JPA Module
   –   BV Module
   –   I18n-Message Module
   –   Scripting Module
   –   Test Support Modules
MyFaces CODI in a Nutshell



•   JSF 1.2 and 2.x          • Type-safe View-Configs
•   Type-safety              • Type-safe Navigation
•   Extensibility            • JPA Integration
•   Advanced Scopes          • Dependency Injection
•   Various Events             Support for BV
•   View-Controller          • Advanced I18n
•   JSF 2 Scope Mappings     • Scripting Integration
                             • And more!
CODI - SETUP
Getting CODI up and running


• Add CODI to the project
    – With Maven
        • Add the modules (or the all-in-one package) to the POM
    – Without Maven
        • Download the current dist package
        • Add the modules (or the all-in-one package) to the Classpath of
          the project
•   Start using it!



                      Hint:
                      mvn archetype:generate -DarchetypeCatalog=http://myfaces.apache.org
Getting CODI up and running - Hints


• With JEE 5 and Mojarra use the controlled bootstrapping
  add-on
• Attention (hint for all bean archives):
  Ensure that the libs aren’t duplicated – otherwise the CDI
  implementation will blame ambiguous interceptors, beans,…
CODI SCOPES IN ACTION
CODI Scopes (with OWB) - Performance
Request Scope (as a Comparison) - Details - 2
Request Scope (as a Comparison) - Details - 1
Window-Scope


•   Like an advanced session per Browser-Window/Tab
•   Use it e.g. instead of @SessionScoped
•   Starts automatically with the first access
•   No support for (CODI conversation-)groups
•   Example:

    @WindowScoped
    public class PreferencesBean
      implements Serializable {
      //...
    }
View-Access Scope


• The next page does not use a view-scoped bean
   the bean get un-scoped
• Simple alternative to @ConversationScoped (of CODI)
• Starts automatically with the first access
• No support for (CODI conversation-) groups
• Example

  @ViewAccessScoped
  public class RegistrationWizard
   implements Serializable {
    //...
  }
(Grouped) Conversations


• Every bean is isolated in a separated conversation
• The bean class is the implicit group
• Terminating a conversation un-scopes all beans connected
  with the conversation (per default 1) immediately
• Termination manually via API or automatically via timeout
• Starts automatically with the first access
• Example
  @ConversationScoped
  public class OrderWizard
   implements Serializable {
    //...
  }
Grouped Conversations - 1


• Grouping beans which belong to a logical conversation
  (e.g. a Use-Case) can be grouped together
• One bean can be used for multiple (parallel) use-cases
• @ConversationGroup is a "special" CDI qualifier
• Termination of the group  un-scoping of all bean(s)
• Example 1
  @ConversationScoped
  @ConversationGroup(OrderUseCase.class)
  public class Customer implements Serializable {
    //...
  }
Grouped Conversations - 2


@Produces
@ConversationScoped
@ConversationGroup(UseCase1.class)
public DemoBean createDemoBeanForUseCase1() {
  return new DemoBean("createDemoBeanForUseCase1");
}

@Produces
@ConversationScoped
@ConversationGroup(UseCase2.class)
public DemoBean createDemoBeanForUseCase2() {
  return new DemoBean("createDemoBeanForUseCase2");
}
Closing vs. Restarting Conversations - 1


• Conversation#close
  Closes a conversation immediately
• Conversation#restart
  Un-scopes all beans of the conversation but internal
  data-structures are intact for using it again
  (better performance)
• Example

   @Inject
   private Conversation conversation;
   //...
   this.conversation.close();
@CloseConversationGroup


• @CloseConversationGroup
  Interceptor for closing a conversation group e.g.
  after a method-invocation or based on a given exception.
• Examples:
   @CloseConversationGroup
   public void registerUser () {}

   @CloseConversationGroup(group = UseCase1.class)
   public void registerUser () {}

   @CloseConversationGroup(
     group = UseCase1.class, on = MyException.class)
   public void registerUser () {}
CODI CONVERSATION - INSIGHTS
Optional Configuration


• CodiConfig
   – WindowContextConfig
      •   getWindowContextTimeoutInMinutes
      •   isUnknownWindowIdsAllowed
      •   getMaxWindowContextCount
      •   isCloseEmptyWindowContextsEnabled
      •   is*EventEnabled
      •   …
   – ConversationConfig
      • getConversationTimeoutInMinutes
      • is*EventEnabled
      • …
   – …
WindowScoped vs WindowContext


• The Window-Context represents the whole window including
  all scopes which are bound to it
• Window-scoped beans are just a part of the current window
• WindowContext API allows to manage the current window
• Example

  @Inject
  private WindowContext windowContext;
  //...
  this.windowContext.getId();
  this.windowContext.closeConversations();
Window-Context

                                   Window(-Context)
                                       API and SPI


    [Scope]            [Scope]             [Scope]          [Scope]    [Scope]

   Window            Conversation       Conversation        View-      View-
                        Group:            Group:            Access     Access
                        Bean1            UseCase1




                                                              Bean 3




                                                                         Bean 4
   Bean 1

            Bean 2




                          Bean 1




                                          Bean 1

                                                   Bean 2

                                       Attributes
Powerful SPI


•   WindowContextManagerFactory
•   WindowContextFactory
•   WindowContextQuotaHandler
•   WindowHandler
•   ConversationFactory
•   WindowContextManager
•   BeanEntryFactory
•   …
Optional Events


• WindowContextEvent
   – CreateWindowContextEvent
   – CloseWindowContextEvent
• ConversationEvent
   – StartConversationEvent
   – RestartConversationEvent
   – CloseConversationEvent
• BeanEvent
   – ScopeBeanEvent
   – AccessBeanEvent
   – UnscopeBeanEvent
TELL US YOUR USE-CASES!
Links


•   http://myfaces.apache.org/extensions/cdi/
•   https://cwiki.apache.org/confluence/display/EXTCDI/Index
•   https://svn.apache.org/repos/asf/myfaces/extensions/cdi/
•   http://twitter.com/MyFacesTeam
•   http://myfaces.apache.org/extensions/cdi/mail-lists.html
•   Recommended
    – http://openwebbeans.apache.org
    – http://code.google.com/a/apache-extras.org/p/
      myfaces-codi-addons/
    – http://os890.spaaze.com/myfaces-codi

More Related Content

PDF
Make JSF more type-safe with CDI and MyFaces CODI
PDF
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
PDF
Apache DeltaSpike
PDF
OpenWebBeans and DeltaSpike at ApacheCon
PDF
MyFaces Universe at ApacheCon
PDF
Apache DeltaSpike the CDI toolbox
PDF
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI
PPTX
Make JSF more type-safe with CDI and MyFaces CODI
MyFaces CODI and JBoss Seam3 become Apache DeltaSpike
Apache DeltaSpike
OpenWebBeans and DeltaSpike at ApacheCon
MyFaces Universe at ApacheCon
Apache DeltaSpike the CDI toolbox
Migrating a JSF-Based Web Application from Spring 3 to Java EE 7 and CDI

What's hot (20)

PDF
Liferay maven sdk
PPTX
Maven for Dummies
PDF
Polygot Java EE on the GraalVM
PPT
Introduction tomaven
PDF
Note - Apache Maven Intro
PPT
Java build tool_comparison
PPTX
Java EE 8
PDF
Intelligent Projects with Maven - DevFest Istanbul
KEY
OSGi in 5 minutes
PPT
Maven basic concept
PDF
Spring - CDI Interop
PPTX
Maven ppt
PDF
Turn you Java EE Monoliths into Microservices with WildFly Swarm
PDF
Java(ee) mongo db applications in the cloud
PDF
Intro To OSGi
PDF
Spring 4 on Java 8 by Juergen Hoeller
PDF
OSGi Presentation
PPTX
Learning Maven by Example
PPTX
Maven tutorial
PPTX
From JavaEE to AngularJS
Liferay maven sdk
Maven for Dummies
Polygot Java EE on the GraalVM
Introduction tomaven
Note - Apache Maven Intro
Java build tool_comparison
Java EE 8
Intelligent Projects with Maven - DevFest Istanbul
OSGi in 5 minutes
Maven basic concept
Spring - CDI Interop
Maven ppt
Turn you Java EE Monoliths into Microservices with WildFly Swarm
Java(ee) mongo db applications in the cloud
Intro To OSGi
Spring 4 on Java 8 by Juergen Hoeller
OSGi Presentation
Learning Maven by Example
Maven tutorial
From JavaEE to AngularJS
Ad

Similar to MyFaces CODI Conversations (20)

PDF
CDI Best Practices with Real-Life Examples - TUT3287
PDF
Effectively using Open Source with conda
KEY
The future of enterprise dependency injection: Contexts & Dependency Injectio...
PDF
BP-7 Share Customization Best Practices
PDF
Survey of Container Build Tools
PDF
Apache Maven - eXo TN presentation
PPTX
Version Control and Continuous Integration
PDF
Lorraine JUG (1st June, 2010) - Maven
PPTX
Spring introduction
PDF
BP-9 Share Customization Best Practices
PDF
Monoliths are so 2001 – What you need is Modularity
PDF
Starting from scratch in 2017
PPTX
How maven makes your development group look like a bunch of professionals.
PDF
Organizing Your PHP Projects (2010 ConFoo)
PDF
Cocoapods in action
PDF
Symfony Live San Francisco 2017 - Symfony @ OpenSky
PDF
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
PDF
Organinzing Your PHP Projects (2010 Memphis PHP)
PDF
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
PDF
Zend Framework 2, What's new, Confoo 2011
CDI Best Practices with Real-Life Examples - TUT3287
Effectively using Open Source with conda
The future of enterprise dependency injection: Contexts & Dependency Injectio...
BP-7 Share Customization Best Practices
Survey of Container Build Tools
Apache Maven - eXo TN presentation
Version Control and Continuous Integration
Lorraine JUG (1st June, 2010) - Maven
Spring introduction
BP-9 Share Customization Best Practices
Monoliths are so 2001 – What you need is Modularity
Starting from scratch in 2017
How maven makes your development group look like a bunch of professionals.
Organizing Your PHP Projects (2010 ConFoo)
Cocoapods in action
Symfony Live San Francisco 2017 - Symfony @ OpenSky
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
Organinzing Your PHP Projects (2010 Memphis PHP)
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Zend Framework 2, What's new, Confoo 2011
Ad

More from os890 (7)

PDF
Flexibilitaet mit CDI und Apache DeltaSpike
PDF
MyFaces Extensions Validator r4 news
PDF
MyFaces CODI v0.9.0 News
PDF
MyFaces Extensions Validator r3 News
PDF
Metadatenbasierte Validierung
PDF
MyFaces Extensions Validator 1.x.2 News
PDF
MyFaces Extensions Validator Part 1 of 3
Flexibilitaet mit CDI und Apache DeltaSpike
MyFaces Extensions Validator r4 news
MyFaces CODI v0.9.0 News
MyFaces Extensions Validator r3 News
Metadatenbasierte Validierung
MyFaces Extensions Validator 1.x.2 News
MyFaces Extensions Validator Part 1 of 3

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PPTX
A Presentation on Artificial Intelligence
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mushroom cultivation and it's methods.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
Tartificialntelligence_presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Approach and Philosophy of On baking technology
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Empathic Computing: Creating Shared Understanding
A Presentation on Artificial Intelligence
Reach Out and Touch Someone: Haptics and Empathic Computing
Mushroom cultivation and it's methods.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
1. Introduction to Computer Programming.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Heart disease approach using modified random forest and particle swarm optimi...
Tartificialntelligence_presentation.pptx
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Approach and Philosophy of On baking technology
SOPHOS-XG Firewall Administrator PPT.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Spectroscopy.pptx food analysis technology
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11

MyFaces CODI Conversations

  • 1. MyFaces CODI Scopes Use the right scopes for your CDI beans
  • 2. Agenda • The History • CODI in a Nutshell • CODI Setup • CODI Scopes in Action • Coding • CODI Conversation - Insights • Your Use-Cases
  • 4. Scopes of the Servlet Spec Application Session Custom Scopes Request
  • 5. CODI Scope Overview Application Session Window Conversation View-Access Request
  • 6. Why custom Scopes? • Request scope too short for most UI-Use-Cases • Session scope – Too long – No support for multi-window applications • Different (conversation) concepts available – MyFaces Orchestra – CDI Conversation Scope – MyFaces CODI Scopes • Conversation Scope • View-Access Scope • Window Scope
  • 7. MyFaces Orchestra • CODI is NOT Orchestra.NEXT • Orchestra is for Spring (only) • CODI is for CDI (only) • Orchestra introduced great concepts!  CODI was planned as "type-safe Orchestra" for CDI Now it’s way more (in most areas) but without Persistence-Management!
  • 8. What‘s about @ConversationScoped of CDI? • Completely broken for several use-cases! • More like inflexible sessions per window • Some of the disadvantages – Overhead e.g. with failed conversion/validation – Lazy termination (after the rendering process) – Restarting conversations during a request isn’t possible – End the whole conversation or nothing – An explicit start is required – Manual check if conversation has been started • Test them with your use-cases!  use them or forget them 
  • 9. MyFaces CODI - Overview • MyFaces Extensions CDI aka MyFaces CODI is a portable CDI extension which can be used with Apache OpenWebBeans, JBoss Weld,… and in combination with other portable CDI extensions • CODI-Core is required in any case • Modules – JSF Module (for 1.2 and 2.0 and 2.1) – JPA Module – BV Module – I18n-Message Module – Scripting Module – Test Support Modules
  • 10. MyFaces CODI in a Nutshell • JSF 1.2 and 2.x • Type-safe View-Configs • Type-safety • Type-safe Navigation • Extensibility • JPA Integration • Advanced Scopes • Dependency Injection • Various Events Support for BV • View-Controller • Advanced I18n • JSF 2 Scope Mappings • Scripting Integration • And more!
  • 12. Getting CODI up and running • Add CODI to the project – With Maven • Add the modules (or the all-in-one package) to the POM – Without Maven • Download the current dist package • Add the modules (or the all-in-one package) to the Classpath of the project • Start using it! Hint: mvn archetype:generate -DarchetypeCatalog=http://myfaces.apache.org
  • 13. Getting CODI up and running - Hints • With JEE 5 and Mojarra use the controlled bootstrapping add-on • Attention (hint for all bean archives): Ensure that the libs aren’t duplicated – otherwise the CDI implementation will blame ambiguous interceptors, beans,…
  • 14. CODI SCOPES IN ACTION
  • 15. CODI Scopes (with OWB) - Performance
  • 16. Request Scope (as a Comparison) - Details - 2
  • 17. Request Scope (as a Comparison) - Details - 1
  • 18. Window-Scope • Like an advanced session per Browser-Window/Tab • Use it e.g. instead of @SessionScoped • Starts automatically with the first access • No support for (CODI conversation-)groups • Example: @WindowScoped public class PreferencesBean implements Serializable { //... }
  • 19. View-Access Scope • The next page does not use a view-scoped bean  the bean get un-scoped • Simple alternative to @ConversationScoped (of CODI) • Starts automatically with the first access • No support for (CODI conversation-) groups • Example @ViewAccessScoped public class RegistrationWizard implements Serializable { //... }
  • 20. (Grouped) Conversations • Every bean is isolated in a separated conversation • The bean class is the implicit group • Terminating a conversation un-scopes all beans connected with the conversation (per default 1) immediately • Termination manually via API or automatically via timeout • Starts automatically with the first access • Example @ConversationScoped public class OrderWizard implements Serializable { //... }
  • 21. Grouped Conversations - 1 • Grouping beans which belong to a logical conversation (e.g. a Use-Case) can be grouped together • One bean can be used for multiple (parallel) use-cases • @ConversationGroup is a "special" CDI qualifier • Termination of the group  un-scoping of all bean(s) • Example 1 @ConversationScoped @ConversationGroup(OrderUseCase.class) public class Customer implements Serializable { //... }
  • 22. Grouped Conversations - 2 @Produces @ConversationScoped @ConversationGroup(UseCase1.class) public DemoBean createDemoBeanForUseCase1() { return new DemoBean("createDemoBeanForUseCase1"); } @Produces @ConversationScoped @ConversationGroup(UseCase2.class) public DemoBean createDemoBeanForUseCase2() { return new DemoBean("createDemoBeanForUseCase2"); }
  • 23. Closing vs. Restarting Conversations - 1 • Conversation#close Closes a conversation immediately • Conversation#restart Un-scopes all beans of the conversation but internal data-structures are intact for using it again (better performance) • Example @Inject private Conversation conversation; //... this.conversation.close();
  • 24. @CloseConversationGroup • @CloseConversationGroup Interceptor for closing a conversation group e.g. after a method-invocation or based on a given exception. • Examples: @CloseConversationGroup public void registerUser () {} @CloseConversationGroup(group = UseCase1.class) public void registerUser () {} @CloseConversationGroup( group = UseCase1.class, on = MyException.class) public void registerUser () {}
  • 26. Optional Configuration • CodiConfig – WindowContextConfig • getWindowContextTimeoutInMinutes • isUnknownWindowIdsAllowed • getMaxWindowContextCount • isCloseEmptyWindowContextsEnabled • is*EventEnabled • … – ConversationConfig • getConversationTimeoutInMinutes • is*EventEnabled • … – …
  • 27. WindowScoped vs WindowContext • The Window-Context represents the whole window including all scopes which are bound to it • Window-scoped beans are just a part of the current window • WindowContext API allows to manage the current window • Example @Inject private WindowContext windowContext; //... this.windowContext.getId(); this.windowContext.closeConversations();
  • 28. Window-Context Window(-Context) API and SPI [Scope] [Scope] [Scope] [Scope] [Scope] Window Conversation Conversation View- View- Group: Group: Access Access Bean1 UseCase1 Bean 3 Bean 4 Bean 1 Bean 2 Bean 1 Bean 1 Bean 2 Attributes
  • 29. Powerful SPI • WindowContextManagerFactory • WindowContextFactory • WindowContextQuotaHandler • WindowHandler • ConversationFactory • WindowContextManager • BeanEntryFactory • …
  • 30. Optional Events • WindowContextEvent – CreateWindowContextEvent – CloseWindowContextEvent • ConversationEvent – StartConversationEvent – RestartConversationEvent – CloseConversationEvent • BeanEvent – ScopeBeanEvent – AccessBeanEvent – UnscopeBeanEvent
  • 31. TELL US YOUR USE-CASES!
  • 32. Links • http://myfaces.apache.org/extensions/cdi/ • https://cwiki.apache.org/confluence/display/EXTCDI/Index • https://svn.apache.org/repos/asf/myfaces/extensions/cdi/ • http://twitter.com/MyFacesTeam • http://myfaces.apache.org/extensions/cdi/mail-lists.html • Recommended – http://openwebbeans.apache.org – http://code.google.com/a/apache-extras.org/p/ myfaces-codi-addons/ – http://os890.spaaze.com/myfaces-codi