I have implemented a CDI Bean which is observing events from another bean:
@SessionScoped
public class FixedItemController implements Serializable {
....
public void onWorkflowEvent(@Observes WorkflowEvent workflowEvent) throws AccessDeniedException {
logger.info("evaluate event...");
....
}
....
}
This works fine as long as I am using the bean in a JSF page with its default name 'fixedItemController'.
But if I declare another instance of that bean in the faces-config.xml like this:
<managed-bean>
<managed-bean-name>myOrderItemController</managed-bean-name>
<managed-bean-class>org.imixs.marty.workflow.FixedItemController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>childItemProperty</property-name>
<property-class>java.lang.String</property-class>
<value>_orderItems</value>
</managed-property>
</managed-bean>
the second instance (myOrderItemController) is not registered automatically as an observer for my WorkflowEvent.
What can I do, to ensure that my second instance - declared by the faces-config.xml - will be immediately instantiated and registered as an observer to my workitemEvent?
faces-config.xml
does not register CDI managed beans. It registers JSF managed beans. Effectively, your #{myOrderItemController}
is a JSF managed bean. It's like as if you use @ManagedBean
instead of @Named
. The JSF bean management facility does not scan for CDI specific @Observes
annotation.
Keep it a CDI managed bean. Whatever you tried to solve for which you thought that registering it in faces-config.xml
would be the right solution has to be solved differently using the CDI API instead of the JSF API.