managed-bean

What is the equivalent of @ManagedBean(eager=true) in CDI

青春壹個敷衍的年華 提交于 2019-11-30 19:25:49
As we all know that it is recommended to use annotations from javax.enterprise.context instead of javax.faces.bean as they are getting deprecated. And we all found ManagedBeans with eager="true" annotated with @ApplicationScoped from javax.faces.bean and having a @PostConstruct method are very useful to do web application initialization e.g: read properties from file system, initialize database connections, etc... Example : import javax.faces.bean.ApplicationScoped; import javax.faces.bean.ManagedBean; import javax.annotation.PostConstruct; @ApplicationScoped @ManagedBean(eager=true) public

Injecting one view scoped bean in another view scoped bean causes it to be recreated

ぐ巨炮叔叔 提交于 2019-11-30 15:21:22
问题 I need to use some data saved in a view scoped bean in an other view scoped bean. @ManagedBean @ViewScoped public class Attivita implements Serializable { // } and @ManagedBean @ViewScoped public class Nota implements Serializable { @ManagedProperty("#{attivita}") private Attivita attivita; // Getter and setter. } Now, maybe my theory about it is still quite poor, I have noticed that when #{attivita} is injected, the Attivita constructor is invoked and thus creating another instance. Is it

Can CDI managed beans and JSF managed beans talk to each other?

女生的网名这么多〃 提交于 2019-11-30 14:49:56
I have a Tomcat 6 JSF web application that I'd like to set up with CDI beans. I will have to convert the project to CDI gradually though. My question is: can CDI beans and traditional JSF managed beans be injected into each other? Thanks. jan groth All JSF managed beans (JMB) either are CDI managed beans (CMB) automatically, or can be recognized as such using the beans.xml marker file. (The requirements of a CMB are set very low and basically just dictate the existence of a non-parameter constructor .) This means that you should be able to use (read: inject) all JMBs with almost no extra

Injecting one view scoped bean in another view scoped bean causes it to be recreated

早过忘川 提交于 2019-11-30 13:52:23
I need to use some data saved in a view scoped bean in an other view scoped bean. @ManagedBean @ViewScoped public class Attivita implements Serializable { // } and @ManagedBean @ViewScoped public class Nota implements Serializable { @ManagedProperty("#{attivita}") private Attivita attivita; // Getter and setter. } Now, maybe my theory about it is still quite poor, I have noticed that when #{attivita} is injected, the Attivita constructor is invoked and thus creating another instance. Is it the right behaviour? What about if I want to reference the same instance and not create a new one? This

Retrieve the web app root path in JSF Managed Bean

人盡茶涼 提交于 2019-11-30 13:00:24
Im trying to access the example/web folder (see below in the image) in a jsf managed bean but cant seem to find a way to do it thx BalusC If you want to get it as a File for some reason, then you need ExternalContext#getRealPath() . This converts a relative web path to an absolute disk file system. Since you need the web's root folder, just pass in / : String absoluteWebPath = externalContext.getRealPath("/"); File webRoot = new File(absoluteWebPath); // ... Unrelated to the concrete problem, whatever functional requirement you've had in mind for which you thought that having an absolute local

com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean

夙愿已清 提交于 2019-11-30 11:39:08
I have a JSF managedbean I am getting the error when a managed bean is referred from from JSF page in WebSphere AppServer. <h:inputText value=#{bean}/> The bean is defined in the faces-config.xml as <managed-bean> <managed-bean-name>bean</managed-bean-name> <managed-bean-class>com.test.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> This is the exception: com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean mailingCitySuggestions Update : this is the stacktrace: com.sun.faces.mgbean

Access session scoped JSF managed bean in web filter

ⅰ亾dé卋堺 提交于 2019-11-30 11:21:04
I have SessionScoped bean called userSession to keep track of the user ( username, ifLogged, etc). I want to filter some pages and therefore I need to access the bean from the webFilter I created. How do I do that? I looks like its even impossible to import the bean to be potenitally visible. BalusC Under the covers, JSF stores session scoped managed beans as an attribute of the HttpSession with the managed bean name as key. So, provided that you've a @ManagedBean @SessionScoped public class User {} , just this should do inside the doFilter() method: HttpSession session = ((HttpServletRequest)

Canonical way to obtain CDI managed bean instance: BeanManager#getReference() vs Context#get()

让人想犯罪 __ 提交于 2019-11-30 10:24:29
问题 I figured that there are two general ways to obtain an auto-created CDI managed bean instance via BeanManager when having solely a Bean<T> to start with (which is created based on Class<T> ): By BeanManager#getReference(), which is more often shown in snippets: Bean<TestBean> bean = (Bean<TestBean>) beanManager.resolve(beanManager.getBeans(TestBean.class)); TestBean testBean1 = (TestBean) beanManager.getReference(bean, bean.getBeanClass(), beanManager.createCreationalContext(bean)); By

Eager ApplicationScoped managed beans constructed multiple times

混江龙づ霸主 提交于 2019-11-30 10:01:48
I have a bunch of eager ApplicationScoped managed beans. Some of them are injected into others by the ManagedProperty annotation, forming a tree of dependencies. Each depending bean manipulates its parent after construction. However, it seems like a new instance is created for each injection, thus making previous manipulations undone. To my understanding, an ApplicationScoped bean should only be created once. Have I misunderstood or why is this happening? Is it because they are eager? Here is an example: ParentBean.java package example; import javax.annotation.PostConstruct; import javax.faces

WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default

徘徊边缘 提交于 2019-11-30 07:53:31
I'm a Java EE-newbie. I want to test JSF and therefore made a simple program but can not deploy it. I get the following error message: cannot Deploy onlineshop-war deploy is failing=Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001408: Unsatisfied dependencies for type Customer with qualifiers @Default at injection point [BackedAnnotatedField] @Inject private de.java2enterprise.onlineshop.RegisterController.customer at de.java2enterprise.onlineshop.RegisterController.customer(RegisterController.java:0) . Please see server.log for more details.