cdi

CDI @Produces with multiple properties files

时间秒杀一切 提交于 2019-12-21 21:32:42
问题 Thanks to this post, https://stackoverflow.com/a/28047512/1227941 I am now using CDI to make msg available in my @Named beans like this: @RequestScoped public class BundleProducer { @Produces public PropertyResourceBundle getBundle() { FacesContext context = FacesContext.getCurrentInstance(); return context.getApplication().evaluateExpressionGet(context, "#{msg}", PropertyResourceBundle.class); } } With Injection like: @Inject private PropertyResourceBundle bundle; The question: What should I

CDI @Produces with multiple properties files

筅森魡賤 提交于 2019-12-21 21:26:00
问题 Thanks to this post, https://stackoverflow.com/a/28047512/1227941 I am now using CDI to make msg available in my @Named beans like this: @RequestScoped public class BundleProducer { @Produces public PropertyResourceBundle getBundle() { FacesContext context = FacesContext.getCurrentInstance(); return context.getApplication().evaluateExpressionGet(context, "#{msg}", PropertyResourceBundle.class); } } With Injection like: @Inject private PropertyResourceBundle bundle; The question: What should I

Using @Transactional with EJBs

房东的猫 提交于 2019-12-21 20:04:38
问题 Is it ok to use @Transactional with EJBs? Is there any difference between using @TransactionAttribute ? I found already here Difference between @Transactional and @TransactionAttribute that @Transactional is for POJO. I've used it accidently for EJB in Wildfly and there were no errors. I wonder whether the behaviour would be the same or if there are some differences. Or maybe @Transactional would be just ignored and default level of @TransactionAttribute would be used? I've search in the spec

what is the purpose of including empty beans.xml in CDI implemenations projects?

て烟熏妆下的殇ゞ 提交于 2019-12-21 17:43:38
问题 I am using weld ,a RI of CDI as dependency injection component in my JSF-EJB-JPA web app. I see in my project we have empty beans.xml in META-INF/beans.xml in ejb.jar and WEB-INF/beans.xml in my WAR. I don't get it why we need to keep empty beans.xml when there nothing defined in that file? 回答1: CDI needs to scan all the classes of a bean archive at start-up and fire a bunch of events because almost any class is automatically a managed bean (read more here), even if it doesn't have any

Inject Bean into CDI Context programmatically?

感情迁移 提交于 2019-12-21 13:05:10
问题 Is it possible to manually Inject a bean into a CDI context? With the JBoss Seam framework, I could always do something like Contexts.getConversationContext().set("foo", bar); and the Bean would become part of that context. Is it possible to do something like this in Java EE 6 CDI? 回答1: There is no way to do this in an implementation agnostic way. You'd have to dig into the implementation, find the scope objects, pull them out via a BeanManager and figure out how to add them. Not all of them

“Unable to convert ejbRef for ejb” on CDI (Weld) injection of @Stateless EJB into @SessionScoped JSF2 bean in Glassfish

99封情书 提交于 2019-12-21 12:33:10
问题 [ UPDATE : After discussion on the Glassfish forums/ML at http://forums.java.net/jive/thread.jspa?messageID=480532 a bug was filed against Glassfish https://glassfish.dev.java.net/issues/show_bug.cgi?id=13040 for this issue.] I'm trying to inject a local no-interface view of a @Stateless EJB into a JSF2 @Named @javax.enterprise.context.SessionScoped backing bean. The EJB is one of several that extend an abstract generic base class. Injection of "@Inject TheEJBClass varName" fails with "Unable

Can CDI be lessened towards Java SE?

China☆狼群 提交于 2019-12-21 11:28:35
问题 JSR-330 dependency injection can be applied to both Java SE and Java EE environments, while JSR-299 is titled "Contexts and Dependency Injection for the Java EE platform". Except strictly Java EE-oriented features, what CDI features make sense on Java SE as well? Any examples available? Thanks! [Revised] Here's Weld on JSE. 回答1: Except strictly Java EE-oriented features, what CDI features make sense on Java SE as well? Any examples available? Thanks! Well, the one mentioned in the Weld

WELD-001303 No active contexts for scope type javax.faces.view.ViewScoped

独自空忆成欢 提交于 2019-12-21 06:29:55
问题 I have switched to javax.enterprise.context.SessionScoped to javax.faces.view.ViewScoped Upgraded faces 2.1 to 2.2 to be able to use ViewScoped with my CDI injections. After I switched to ViewScoped I have started getting this error and I can't figure out why! Do you think there is something wrong here? Glassfish 3.1.2, Primefaces 3.4.2, JSF 2.2 org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.faces.view.ViewScoped The button opens the page

Are Java EE 6 CDI events transactional?

巧了我就是萌 提交于 2019-12-21 03:39:43
问题 Are Java EE 6 CDI events transactional? If I fire an event in a transaction, and subsequently roll back the transaction, are the effects of the Event listener rolled back as well? Is this behaviour dependent on the event listener itself supporting transactions? What about if I try and roll-back the exception from within then event listener, does it roll-back the transaction that fired the event? 回答1: From the events chapter of the CDI 1.0 specification, one can define an event to be

What is Weld, JSR-299?

醉酒当歌 提交于 2019-12-21 03:24:08
问题 I've found lots of tutorials showing Weld code samples, but not an introductory overview. Could you please suggest an introductory article, or answer the following: What does Weld do/give you? How does it relate to Java EE 6? How would one use it in a Java EE 6 project? If one uses it in a Java EE 6 project, what is it supplanting, if anything? 回答1: What does Weld do/give you? Weld is the reference implementation of the abstract JSR-299 API, which is better known as CDI, Contexts and