vineri, 10 iunie 2016

CDI-JSF: Referencing a producer method via an EL name

Here it is an example of using referencing a producer method via an EL name. The EL expressions used in the JSF page:

#{someFoo}
#{moreFoo}

The Foo qualifier:

@Qualifier
@Retention(RUNTIME)
@Target({METHOD, FIELD, PARAMETER, TYPE})
public @interface Foo {
}

And the bean containing the producer method:

@Named
@ApplicationScoped
public class TheBean {

 @Produces
 @Named
 @Foo
 String getSomeFoo() {
  return "foo";
 }       
   
 @Produces
 @Named("moreFoo")
 @Foo
 String getExtraFoo() {
  return "extra-foo";
 }  
}

The complete example is available here.

2 comentarii: