Skip to main content

Posts

Showing posts with the label CDI

HTML5 support in JSF 2.2 with Bean Validation 1.1 (JavaEE 7)

In this post i will show the HTML5 Support given by JSF 2.2, Which is part of Java EE 7 Spec. Also how to integrate the Bean Validation 1.1 feature with help of CDI (Contexts and Dependency Injection) 1.1 spec. Before going the HTML5 support, my earlier posts on JSF, i used @ManagedBean annotation, because its part of Managed Bean Specification (Java EE 6). Another Reason i used Tomcat as a primary container, if i used Managed Bean Spec then its part of Mojjara implementation, so no need to add more CDI specific (Jboss Weld lib) lib to class-path. But from Java EE 7 on-wards, JCP community expand the CDI capabilities and make CDI as important spec in Java EE 7 and Managed Bean spec is deprecated in favor of CDI . so they recommend to use CDI wherever its possible. so our future all post to target the CDI. next post i will show how add the CDI capability to tomcat container.

Contexts and Dependency Injection Series

Contexts and Dependency Injection (CDI )  JSR 299  is a new feature in Java EE 6 Web Profile .  Its Enhance the JSR 330 Dependency Injection in Java. CDI are highly used annotation. CDI makes Loose coupling between classes. To use javax.inject.Inject annotation, we can inject any class into another classes  i put 4 part series of CDI, you can get it here Learning CDI (Contexts and Dependency Injection) Part 1 Learning CDI (Contexts and Dependency Injection) Part 2 Learning CDI (Contexts and Dependency Injection) Part 3 Learning CDI (Contexts and Dependency Injection) Part 4

Understanding CDI (Contexts and Dependency Injection) Part 4

This is Fourth  part of CDI discussion.Please visit   part one ,  part two  and    part three Interceptors Interceptors is one feature of CDI. Using this feature we can intercept the method call. Its counterpart technique for Aspect Oriented Programming (AOP) in Spring. Its helps to analysis the business methods and these interceptors are disabled by default. so we can enable/disable the interceptor in deployment time through beans.xml  file. Create interceptor      To create interceptor involves two step process. first to create interceptor binding and  implement the interceptors. here we create Log Interceptor, so we need to create Log Interceptor Binding(its  like qualifier) Log.java here @InterceptorBinding is represent that the annotation 'Log' is interceptor second, we need to implement the interceptors LogImpl.java here @Interceptor represent that its interceptor implementation @Log specifies to which interceptor  implementation , both of these lin

Understanding CDI (Contexts and Dependency Injection) Part 3

This is Third  part of CDI discussion.Please visit   first part  and part two , @Alternative In part two  we seen @qualifier 's to resolve the unambiguous problem for one interface and more than on implementation. In qualifier helps to solve in development time. (i.e all meta information is stored in class files). Another solution is @Alternative annotation solve the problem in  deployment  time. all configuration is stored in beans.xml in WEB-INF folder We take same example what we discussed in last part  one interface (Hello) and two implementation(HelloImplOne, HelloImplTwo) here i marked @Alternative in both implementation Hello Interface HelloImplOne Implementation HelloImplTwo Implementation and go and modify the beans.xml in WEB_INF folder In <alternatives> tag in beans.xml we need specify which one need to inject. See the screen cast for demo Comments are welcomed

Learning CDI (Contexts and Dependency Injection) Part 2

This is second part of CDI discussion. If u r not visited, Please visit first part , Qualifier            Its annotation, its helps to create our qualifier annotation. We already seen if we have more than one implementation of particular interface then we can't inject, because ambiguity issues are arise. so we need to define own qualifiers and marked the annotation with that qualifier. When inject we need to mention the qualifier. For Example We have one interface and two implementation Hello Interface HelloImplOne Implementation HelloImplTwo Implementation  In Injection  Point (i.e where u inject the class, i.e where u use @inject key word) if u try to inject using interface like this u get AmbiguousResolutionException. but we can still use like this @javax.inject.Inject HelloImplOne hello; @javax.inject.Inject HelloImplTwo hello; so we need use qualifier we can create own qulaifier like any class here @Qualifier - is annotation to rep

Learning CDI (Contexts and Dependency Injection) Part 1

Please see the second part  here Contexts and Dependency Injection (CDI )  JSR 299  is a new feature in Java EE 6 Web Profile .  Its Enhance the JSR 330 Dependency Injection in Java. CDI are highly used annotation. CDI makes Loose coupling between classes. To use javax.inject.Inject annotation, we can inject any class into another classes     In traditional way, we create the instance using ' new ' operator in another class. here thats instance life time is dependent on target class. its tightly coupled. Here CDI makes to loosely coupled and change the life-cycle for that instance.