miercuri, 4 februarie 2015

[OmniFaces utilities (2.0)] Get the CDI managed bean instance (actual) of the given bean representation (decide to create one if it doesn't exist)


[OmniFaces utilities] The getInstance() returns the CDI managed bean instance (actual) of the given bean representation and creates one if one doesn't exist and create argument is true, otherwise don't create one and return null if there's no current instance.

Method:
Usage:

import org.omnifaces.util.Beans;
import javax.enterprise.inject.spi.Bean;
...
// in/out CDI bean TestBean
// if the second parameter is false and there's no current instance, then it will return null
Bean<TestBean> testBeanRep = Beans.resolve(TestBean.class);
TestBean testBean = Beans.getInstance(testBeanRep, true);

Niciun comentariu:

Trimiteți un comentariu