apache deltaspikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · agenda •cdi...
TRANSCRIPT
![Page 1: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/1.jpg)
Mark Struberg / INSO, TU Vienna
Apache DeltaSpike...closes the gap
![Page 2: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/2.jpg)
About the Speakers
• http://github.com/struberg
• http://people.apache.org/~struberg
• Apache Software Foundation member
• Apache OpenWebBeans, MyFaces, BVAL, OpenJPA, Maven, DeltaSpike, ...
• CDI EG member
![Page 3: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/3.jpg)
Agenda
• CDI Quickstart• CDI Extensions Howto• DeltaSpike History and Future
• deltaspike-core• deltaspike-cdictrl• deltaspike-jpa• deltaspike-jsf
![Page 4: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/4.jpg)
How the ASF works
• OSS vs closed source• Why is DeltaSpike Open Source?• ALv2
• Non profit Organization• Contributors, Committers, PMC• ASF members, board of directors• often professional support available
![Page 5: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/5.jpg)
About Apache DeltaSpike
• Apache Top Level Project since 2013-04
• Homepage:http://incubator.apache.org/deltaspikehttp://deltaspike.apache.org
• Source:http://git.apache.org/incubator-deltaspike
• [email protected]@deltaspike.apache.org
• irc.freenode.net channel #deltaspike
• https://issues.apache.org/jira/browse/DELTASPIKE
![Page 6: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/6.jpg)
CDI Basics
![Page 7: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/7.jpg)
JSR-299 Overview
• Contexts and Dependency Injection for the Java EE platform (CDI)
• Component Model for Java (SE and EE)
• Originally designed for J2EE but also usable for standalone applications
• Based on JSR-330
![Page 8: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/8.jpg)
CDI Features
• Typesafe Dependency Injection• Interceptors• Decorators
• Events• SPI for Portable Extensions• Unified EL integration
![Page 9: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/9.jpg)
Available Implementations
• JBoss Weld (RI)• Apache OpenWebBeans• Resin CanDI
• Every JavaEE 6 container!• Available CDI-1.1 implementations
– Weld-2.0-alpha (not finished)– OpenWebBeans-2.0 in preparation
![Page 10: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/10.jpg)
A small Example
• Create a META-INF/beans.xml marker file
• Create a MailService implementation@ApplicationScopedpublic class MyMailService implements MailService { private @Inject User usr; public send(String from, String to, String body) { .. do something }}
![Page 11: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/11.jpg)
A small Example
• We also need a User bean@SessionScoped
@Named
public class User {
public String getName() {..}
..
}
![Page 12: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/12.jpg)
A small Example
• Injecting the Bean@RequestScoped@Named(„mailForm“)public class MailFormular { private @Inject MailService mailSvc; private @Inject User usr; public String sendMail() { mailSvc.send(usr.getEmail(), „other“, „sometext“); return “successPage”; }}
![Page 13: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/13.jpg)
A small Example
• Use the beans via Expression Language<h:form>
<h:outputLabel value="username"
for"username"/>
<h:outputText id="username"
value="#{user.name}"/>
<h:commandButton value="Send Mail"
action="#{mailForm.sendMail}"/>
</h:form>
![Page 14: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/14.jpg)
'Singletons', Scopes, Contexts
• Each created Contextual Instance is a 'Singleton' in a well specified Context
• The Context is defined by it's Scope
• @ApplicationScoped ->ApplicationSingleton
• @SessionScoped -> SessionSingleton
• @ConversationScoped -> ConversationSingleton
• @RequestScoped -> RequestSingleton
• ... code your own ...
![Page 15: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/15.jpg)
Portable Extensions
![Page 16: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/16.jpg)
Writing own Extensions
• CDI Extensions are portable• and easy to write!• Are activated by simply dropping
them into the classpath
• CDI Extensions are based on java.util.ServiceLoader MechanismMETA-INF/services/javax.enterprise.inject.spi.Extension
![Page 17: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/17.jpg)
Extension Basics
• During the boot, the BeanManager sends CDI Lifecycle Events to the Extensions
• CDI Extensions can do anything you can do with Annotations. ... and even more!
• Attention:strictly distinguish between boot and runtime!
![Page 18: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/18.jpg)
Extension Lifecycle Events
• Container sends CDI 'system events' which all Extensions can @Observes:– BeforeBeanDiscovery
– ProcessAnnotatedType
– ProcessInjectionTarget
– AfterBeanDiscovery
– AfterDeploymentValidation
– BeforeShutdown
• eat your own dog food: using CDI events for Extensions
![Page 19: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/19.jpg)
Popular Extensions
• Apache MyFaces CODIhttp://myfaces.apache.org/extensions/cdi
• JBoss Seam3http://seamframework.org/Seam3
• Apache DeltaSpikehttps://cwiki.apache.org/confluence/display/DeltaSpike/Indexhttp://incubator.apache.org/deltaspikehttp://deltaspike.apache.org
![Page 20: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/20.jpg)
Apache DeltaSpike History
![Page 21: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/21.jpg)
DeltaSpike Status Quo
• CORE - finished• JPA - finished• CdiCtrl - finished
• JSF - 95%• DeltaSpike Core, CdiCtrl and JPA
already gets used in Production!• Used as base for JBoss projects like
JBoss AearoGear and others.
![Page 22: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/22.jpg)
DeltaSpike Future
• Finish JSF module and release this month
• Spring Bridge
• 2-monthly releases
• What else do you need?Please add it to our feature backlog!
![Page 23: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/23.jpg)
Apache DeltaSpike Core
![Page 24: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/24.jpg)
DeltaSpike CORE
• Solves Core Java problems• Has no external dependencies• Especially no Java EE dependencies
• Base for all other DeltaSpike modules• Too many features to showcase in this
talk...
![Page 25: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/25.jpg)
DeltaSpike CORE Features
• ProjectStage• Configuration• Catch Handler
• Utils• BeanProvider/BeanManagerProvider• conditional Exclude• Typesafe Messages
• ClassDeactivator
![Page 26: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/26.jpg)
DeltaSpike Configuration
• The Problem– default configuration – plus optional plugin configuration– plus optional external configuration– plus, plus, plus, ...– from lots of different ConfigSources
![Page 27: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/27.jpg)
DeltaSpike Configuration
• Pick up information from various places (ConfigSource)
• Ordinal based (deltaspike_ordinal=..): higher number -> more important
• Extensible, register your own ConfigSource
![Page 28: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/28.jpg)
Using the Configuration
• ConfigResolver.getPropertyValue(..)• You can also inject the config:@Inject
@ConfigProperty(name="printerId")
private String printerId;
![Page 29: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/29.jpg)
Own property ConfigSource
• Register your own via ServiceLoader• Easy mechanism for property files:
– implement PropertyFileConfig– picks up all property files with the name
returned in getPropertyFileName() and registers them as ConfigSource
![Page 30: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/30.jpg)
own property config
public class NfcCardProdConfigDefinition implements PropertyFileConfig {
@Override
public String getPropertyFileName() {
return "nfcCardProd.properties";
}
}
![Page 31: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/31.jpg)
Config Ordinals
• PropertyFileConfigSource: 100META-INF/apache-deltaspike.properties
• LocalJndiConfigSource: 200java:comp/env/deltaspike/..
• EnvironmentPropertyConfigSource: 300• SystemPropertyConfigSource: 400• your own config defaults to 1000
![Page 32: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/32.jpg)
Vetoing Beans
• Can be used to dynamically disable a Bean
• Most powerful in combination with– @Alternative– @Specializes
• internally uses: ProcessAnnotatedType#veto()
• Inspired CDI-1.1 feature '@Vetoed'
![Page 33: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/33.jpg)
DeltaSpike @Exclude
• Used to disable bean depending on a certain situation
• @Exclude()
• @Exclude(ifProjectStage=ProjectStage.Production.class)
• @Exclude(exceptIfProjectStage=ProjectStage.Development.class)
• @Exclude(onExpression=”dbVendor!=oracle”)
![Page 34: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/34.jpg)
BeanManagerProvider
• Access to the BeanManager in places where it cannot get injected– JPA Entity Listeners– JSF Components– JMX Beans– ServletListener or ServletFilter if not
running in EE Server
• Will be available in CDI-1.1:CDI.current()
![Page 35: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/35.jpg)
BeanProvider
• internally uses BeanManagerProvider
• #getContextualReference(String);
• #getContextualReference(Type, Qualifiers...);
• #injectFields Used to fill all injection points of a existing instance
![Page 36: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/36.jpg)
Core Utility Classes
• helps for writing own CDI Extensions• BeanBuilder• AnnotatedTypeBuilder
• AnnotationInstanceProviderallows to dynamically create Annotation instances + any values
![Page 37: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/37.jpg)
Apache DeltaSpike CdiCtrl
![Page 38: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/38.jpg)
Container Bootstrap
• Allows to boot CDI containers with a vendor independent API
• Implementations for:– Apache OpenWebBeans– JBoss Weld– Apache OpenEJB (TomEE embedded)– add your own
• Simply replace the impl jar to switch!
![Page 39: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/39.jpg)
Container Bootstrap
• Very usable for unit tests, batches or other standalone Java processes:CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
cdiContainer.boot();
cdiContainer.getContextControl(). startContexts();
![Page 40: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/40.jpg)
Context Control
• Also usable in EE containers• Usage:@Inject ContextControl ctxCtrl;
• Allows to attach dummy RequestContext, SessionContext etc to the current Thread.
• Usable for Quartz extensions or any other async work
![Page 41: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/41.jpg)
Apache DeltaSpike JPA
![Page 42: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/42.jpg)
Interceptors
• An Interceptor decouples technical concerns from business logic
• Applying cross cutting concerns to beans
• JSR-299 allows you to write your own interceptors
• Interceptors are treated as being @Dependent to the intercepted class
![Page 43: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/43.jpg)
Interceptor usage
• Interceptor annotations can be applied on method or class level@ApplicationScoped
public class UserService {
@Transactional
public storeUser(User u) {
...
}
}
![Page 44: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/44.jpg)
InterceptorBinding Type
• InterceptorBindings are used to identify which Interceptors should be applied to a bean@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.TYPE,
ElementType.METHOD })
public @interface Transactional {
}
![Page 45: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/45.jpg)
The Interceptor Impl@Interceptor @Transactional
public class TransactionalInterceptor {
private @Inject EntityManager em;
@AroundInvoke
public Object invoke(InvocationContext context)
throws Exception {
EntityTransaction t = em.getTransaction();
try {
if(!t.isActive()) t.begin();
return context.proceed();
} catch(Exception e) {
.. rollback and stuff
} finally {
if(t != null && t.isActive())
t.commit();
}
}
}
![Page 46: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/46.jpg)
Enabling Interceptors
• Interceptors need to be enabled manually in beans.xml
• You can define the order in which multiple Interceptors stack<beans>
<interceptors>
<class>org.mycomp.Secured</class> <class>org.mycomp.Transactional</class>
</interceptors>
</beans>
![Page 47: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/47.jpg)
DeltaSpike @Transactional
• Handles native EntityManager handling• Handles UserTransaction handling• EntityManager can have any scope:
– @RequestScoped– @TransactionScoped
![Page 48: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/48.jpg)
EntityManagerFactoryProducer
• Uses PersistenceConfigurationProvider to pick up config Properties
• Add a producer for EntityManagerpublic @ApplicationScoped class EntityManagerProducer {
private @Inject @UnitName("MyPU") EntityManagerFactory emf;
@Produces @RequestScoped
public EntityManager createEM() {
return emf.createEntityManager(); }
public void dispose(@Disposes EntityManager em) {
em.close(); }
![Page 49: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/49.jpg)
Apache DeltaSpike JSF
![Page 50: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/50.jpg)
Features
• Typesafe JSF Messages• Typesave Navigation• PageBeans
• @JsfPhaseListener• Browser Tab Support• JSF related CDI events• New Scopes
• ongoing JSF-2.2 integration
![Page 51: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/51.jpg)
Typesafe Messages
@MessageContextConfig( messageSource="myproject.properties")
@MessageBundle
public interface UserMessage {
@MessageTemplate("{hellomsg}")
String sayHello(String name);
}
![Page 52: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/52.jpg)
Typesafe JSF Messages
@Inject
private JsfMessage<UserMessage> msg;
String doAction() {
msg.addInfo().simpleMessageNoParam();
msg.addFatal().
accessNotAllowed(userName, resource);
// or manually:
String message = msg.get().someMsg();
}
![Page 53: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/53.jpg)
DeltaSpike Scopes
• @WindowScoped
• @ViewAccessScoped (in 0.5)
• @ConversationScoped (CODI conv., in 0.5)
• @ViewScoped
• @RenderScoped
![Page 54: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/54.jpg)
Typesafe JSF Navigation@Page(navigation = REDIRECT)
interface Pages extends ViewConfig {
class Index implements Pages{}
@Page(viewParams = INCLUDE)
@Secured(AdminVoter.class)
class Admin implements Pages {}
//'navigation' overruled
@Page(navigation = FORWARD)
class Home implements Pages {}
class CustomErrorPage extends DefaultErrorView {}
}
![Page 55: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/55.jpg)
Using Typesafe Navigation@Model
public class MyBackingBean {
public Class<? extends ViewConfig> overview(){
return Pages.Overview.class;
}
public Class<? extends Pages> goHome(){
return Pages.Home.class;
}
//navigates to /pages/customErrorPage.xhtml
public Class<? extends ViewConfig> showError() {
return DefaultErrorView.class;
}
}
![Page 56: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/56.jpg)
JSF Lifecycle Events
• doSthg(@Observes @AfterJsfRequest FacesContext ct) {
• doSthg(@Observes @BeforeJsfRequest FacesContext ct) {
• doSthg(@Observes @BeforePhase(PhaseId.RESTORE_VIEW) FacesContext ct) {
• doSthg(@Observes @AfterPhase(PhaseId.RESTORE_VIEW) FacesContext ct) {
•
![Page 57: Apache DeltaSpikepeople.apache.org/~struberg/jax2013/apache_deltaspike_jax2013.pdf · Agenda •CDI Quickstart •CDI Extensions Howto •DeltaSpike History and Future •deltaspike-core](https://reader034.vdocument.in/reader034/viewer/2022042219/5ec589ada8184f5b061e1624/html5/thumbnails/57.jpg)
Legal stuff
• Apache, OpenWebBeans, MyFaces, OpenEJB and OpenJPA are trademarks of the Apache Software Foundation
• Seam3 and Weld are trademarks of JBoss Inc
• CanDI is a trademark of Caucho Inc