Class CdiUtils
java.lang.Object
de.xima.fc.utils.CdiUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TgetBeanCreateIfMissing(Class<T> beanClass, Annotation... qualifiers) Returns the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) of the given class.static <T> TgetBeanCreateIfMissingNullIfNotFound(Class<T> beanClass, Annotation... qualifiers) Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does.static <T> Optional<T> getBeanIfExists(Class<T> beanClass, Annotation... qualifiers) Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does.static StringgetBeanName(Class<?> beanClass, Annotation... qualifiers) static <T> TgetBeanNullIfMissing(Class<T> beanClass, Annotation... qualifiers) Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does.
-
Constructor Details
-
CdiUtils
public CdiUtils()
-
-
Method Details
-
getBeanCreateIfMissing
Returns the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) of the given class. When the bean was not created yet, creates the bean.- Type Parameters:
T- Type of the bean to lookup.- Parameters:
beanClass- Class of the bean to lookup.qualifiers- Optional qualifiers for the bean.- Returns:
- The bean instance of the given class.
-
getBeanName
- Parameters:
beanClass- Class of the bean to lookup.qualifiers- Optional qualifiers for the bean.- Returns:
- The name of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped).
-
getBeanIfExists
Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does. When the bean was not created yet, returnsnull.- Type Parameters:
T- Type of the bean to lookup.- Parameters:
beanClass- Class of the bean to lookup.qualifiers- Optional qualifiers for the bean.- Returns:
- The bean instance if the bean was created already, or empty otherwise.
-
getBeanNullIfMissing
Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does. When the bean was not created yet, returnsnull.- Type Parameters:
T- Type of the bean to lookup.- Parameters:
beanClass- Class of the bean to lookup.qualifiers- Optional qualifiers for the bean.- Returns:
- The bean instance if the bean was created already, or
nullotherwise.
-
getBeanCreateIfMissingNullIfNotFound
@Nullable public static <T> T getBeanCreateIfMissingNullIfNotFound(Class<T> beanClass, Annotation... qualifiers) Checks if an instance of the JSF bean (request scoped, view scoped, session scoped, conversation scoped, or application scoped) exists, and returns the bean if it does. When the bean was not created yet, creates and returns the bean. When the class with the qualifiers does not resolve to a bean, returnsnull.- Type Parameters:
T- Type of the bean to lookup.- Parameters:
beanClass- Class of the bean to lookup.qualifiers- Optional qualifiers for the bean.- Returns:
- The bean existing or created instance, or
nullif the class is not managed by CDI.
-