1. Wstęp do CDI
2. Beans
3. Zarządzanie beanami
4. Scopes and context
5. Events
6. Interceptors
7. Decorator
  1. package pl.edu.java.cdi.managedBeans;
  2.  
  3. public interface Greeting {
  4.         String sayHello(String name);
  5. }
  1. package pl.edu.java.cdi.managedBeans;
  2.  
  3. public class MyGreeting implements Greeting {
  4.         @Override
  5.         public String sayHello(String name) {
  6.                 return "Cześć " + name;
  7.         }
  8. }
  9.  
  1. package pl.edu.java.cdi.managedBeans;
  2.  
  3. import javax.decorator.Decorator;
  4. import javax.decorator.Delegate;
  5. import javax.enterprise.inject.Any;
  6. import javax.inject.Inject;
  7.  
  8. @Decorator
  9. public class MyDecorator implements Greeting {
  10.  
  11.     @Inject
  12.     @Delegate
  13.     @Any
  14.     private Greeting greeting;
  15.  
  16.     @Override
  17.     public String sayHello(String name) {
  18.         return greeting.sayHello(name + ", jak się masz?");
  19.     }
  20. }
  21.  
  1. package pl.edu.java.cdi.managedBeans;
  2.  
  3. import javax.enterprise.context.RequestScoped;
  4. import javax.inject.Inject;
  5. import javax.inject.Named;
  6.  
  7. @Named
  8. @RequestScoped
  9. public class MyController {
  10.  
  11.         @Inject
  12.         private Greeting greeting;
  13.        
  14.         public String getDecorate() {
  15.                 return greeting.sayHello("Mateusz");
  16.         }      
  17. }
<decorators>
        <class>pl.edu.java.cdi.managedBeans.MyDecorator</class>
</decorators>
created by cv.java.org.pl © 2023 All Rights Reserved.