jboss-weld

JSF 2.0: use Enum values for selectOneMenu [duplicate]

拈花ヽ惹草 提交于 2019-11-28 16:33:13
This question already has an answer here: How to use enum values in f:selectItem(s) 4 answers I'm using JSF 2.0 and want to fill a selectOneMenu with the values of my Enum. A simple example: // Sample Enum public enum Gender { MALE("Male"), FEMALE("Female"); private final String label; private Gender(String label) { this.label = label; } public String getLabel() { return this.label; } } Unfortunately, i can't use Seam for my current project, which had a nice <s:convertEnum/> Tag that did most of the work. In Seam, to use the values of the Enum, i had to write the following markup (and create a

WELD-000072 Managed bean declaring a passivating scope must be passivation capable

百般思念 提交于 2019-11-28 15:54:48
问题 I wrote a simple program in java web forms but i am receiving the following error: WELD-000072 Managed bean declaring a passivating scope must be passivation capable. Bean: Managed Bean [class BeanPakage.DemoBeans ] with qualifiers [ @Any @Default @Named ] Can anyone tell me where this error comes from? import javax.enterprise.context.SessionScoped; import javax.inject.Named; @Named("DemoBeans") @SessionScoped public class DemoBeans { private String name; public String getName() { return name

How to bootstrap weld-osgi version 2 in SE application

混江龙づ霸主 提交于 2019-11-28 09:58:05
问题 It's really not funny. There is no information in internet how to run weld-osgi second version (2.1.2.final) in se app. Instructions for ver 1 don't work. Let the developers be ashamed that they didn't provide necessary samples. I wrote them here. So, I have and OSGi activator and I want to get beans from it. In GF4 I used this: private BeanManager getBeanManager() throws NamingException { try{ InitialContext initialContext = new InitialContext(); return (BeanManager) initialContext.lookup(

Injecting a Spring bean using CDI @Inject

瘦欲@ 提交于 2019-11-27 22:23:52
I'm trying to inject a bean defined in a Spring context into a CDI managed component but I'm not successful. The bean is not injected, instead a new instance gets created each time the injection should be performed. My environment is Tomcat 7 with JBoss Weld. The Spring ApplicationContext is straighforward: <beans> ... <bean id="testFromSpring" class="test.Test" /> ... </bean> The CDI managed bean looks like this: @javax.inject.Named("testA") public class TestA { @javax.inject.Inject private Test myTest = null; ... public Test getTest() { return this.myTest; } } This is my faces-config.xml

CDI injection in EntityListeners

≯℡__Kan透↙ 提交于 2019-11-27 19:20:34
问题 Since JPA 2.0 does not support injection into EntityListener (JPA 2.1 will), decided to use JNDI lookup to get the BeanManager and through it get the logged in user. I defined an EntityListener similar to this: public class MyEntityListener { public static BeanManager getBeanManager() { try { InitialContext initialContext = new InitialContext(); return (BeanManager) initialContext.lookup("java:comp/BeanManager"); } catch (NamingException e) { e.printStackTrace(); return null; } } public

CDI Application and Dependent scopes can conspire to impact garbage collection?

痴心易碎 提交于 2019-11-27 15:52:52
问题 We're starting to experiment with implementing our backend services using CDI. The scenario is this: EJB with @Startup is started when EAR deployed. An ApplicationScoped bean is injected onto this: @ApplicationScoped public class JobPlatform { private PooledExecutor threadHolder; @Inject @Any private Instance<Worker> workerSource; ... The bean also has an Observer method, which, when an event is observed, gets a worker bean from the Instance workerSource and puts it on the threadPool, where

What is the default scope of a Named CDI bean?

試著忘記壹切 提交于 2019-11-27 15:41:41
问题 Is there any default scope for a @Named CDI bean without additional @...Scoped annotations? I have not found any relevant information in the official Weld documentation. A @Named bean can be accessed over JSF without additional annotations, so some implicit scope seems likely. Thank you 回答1: The default scope is the dependent pseudo-scope @Dependent , as stated in the weld documentation: CDI features the so-called dependent pseudo-scope. This is the default scope for a bean which does not

Maven Eclipse Debug “JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)”

好久不见. 提交于 2019-11-27 14:23:00
问题 I'm trying to debug Maven tests in Eclipse. When I launch tests with the maven option maven.surefire.debug, I get this error : ERROR: transport error 202: bind failed: Address already in use FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197) ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510) JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690] /bin/sh:

How to programmatically inject a Java CDI managed bean into a local variable in a (static) method

自作多情 提交于 2019-11-27 04:12:42
How can I programmatically inject a Java CDI 1.1+ managed bean into a local variable in a static method? To inject an instance of class C : javax.enterprise.inject.spi.CDI.current().select(C.class).get() This is available in CDI 1.1+ Use for instance this utility class . You basically have to obtain instance of BeanManager and than grab the bean you want from it (imagine something like JNDI lookup). Update You could also use CDI utility class offered in CDI 1.1 SomeBean bean = CDI.current().select(SomeBean.class).get(); @BRS import javax.enterprise.inject.spi.CDI; ... IObject iObject = CDI

How to inject a non-serializable class (like java.util.ResourceBundle) with Weld

不想你离开。 提交于 2019-11-27 01:20:24
问题 I want to create a Producer that makes it possible to inject a java.util.ResourceBundle into any class in order to get localized Strings easily. My ResourceBundle-Producer looks like this: public class ResourceBundleProducer { @Inject public Locale locale; @Inject public FacesContext facesContext; @Produces public ResourceBundle getResourceBundle() { return ResourceBundle.getBundle("/messages", locale ) } } The Injection of Locale and FacesContext works (took the corresponding producers from