managed-bean

Migrate JSF managed beans to CDI managed beans

邮差的信 提交于 2019-12-03 12:23:18
I'm planning to convert a web app from using JSF managed bean to using CDI managed beans. I know I'll need to do below: Add a empty beans.xml file in WEB-INF. Replace all JSF @ManagedBean to CDI @Named annotations. Replace all JSF scope annotations with CDI or OmniFaces scope annotations. Replace all JSF @ManagedProperty with CDI @Inject annotations. Is that all that needs to be done? Are there any gotchas that I need to be aware of? Basically, that's indeed all you need to do provided that you're on a Java EE server already. When on Tomcat, you'd need to manually install CDI first.

Getting a path to a resource file from managed-bean in JSF

只谈情不闲聊 提交于 2019-12-03 12:16:02
问题 I have this situation: I am trying to remove an old avatar image for a user before putting a new one from the managed bean. String fileName = "resources/img/useravatars/" + getSessionBean().getSearchAccount().getAvatar(); File f = new File(fileName); I've googled a bit and it seems that I can get a path to that folder from ExternalContext like: FacesContext facesContext = FacesContext.getCurrentInstance(); facesContext.getExternalContext(). ... But I couldn't find an appropriate method from

Injecting same EJB into two different managed beans not working

自古美人都是妖i 提交于 2019-12-03 10:15:40
I have a stateless EJB and two different SessionScoped managed beans. e.g. EJB as follows - @Stateless public classs MyEjb implements MyEjbLocal { @PersistentContext(unitName="myPU") private EntityManager em; and a managed bean - @ManagedBean @SessionScoped public class MyBean1 implements Serializable { @EJB private MyEjbLocal myEjb; and another managed bean - @ManagedBean @SessionScoped public class MyBean2 implements Serilizable { @EJB private MyEjbLocal myEjb; private List<MyEntity> entities; public MyBean2() { entities = myEjb.getAllEntities(); //this is where the problem is, myEjb is null

How to access property of one managed bean in another managed bean

大城市里の小女人 提交于 2019-12-03 09:48:13
问题 I have a managed bean (SessionScope as follow) @ManagedBean(name="login") @SessionScoped public class Login implements Serializable { private String userSession; public Login(){ } } In this managedbean, somewhere in the login function, i store the email as a session. I have another managed bean called ChangePassword (ViewScoped). I need to access the value of the email which is stored in the userSession. The reason of doing so is that i need to find out the current userSession(email) before i

Expire specific managed bean instance after time interval

耗尽温柔 提交于 2019-12-03 08:03:12
I have 2 JSF managed beans A and B and I need to expire/destruct/destroy A after 2 minutes and B after 5 minutes. I checked this related question Timing out from a bean , but it is expiring whole session. I do not want to expire whole session. How can I achieve this with a custom scope? Given that you're using JSF bean management facility (and thus not CDI, which would require a completely different answer), you can achieve this with @CustomScoped . The @CustomScoped value must refer a Map implementation in a broader, usually existing, scope. Something like: @ManagedBean @CustomScoped("#

Using jquery ajax to call a jsf managed bean method (an AjaxBehaviorEvent listener handler)

*爱你&永不变心* 提交于 2019-12-03 07:37:07
i would like to know if there is a way to fire a jsf managed bean method (with an AjaxBehaviorEvent type parameter: the same triggered when using f:ajax) directly by using a jquery ajax server request.By the way , i m a jsf developper and i didn't find an example about using jquery ajax with Java EE as a server-side framework, all examples i found were with php..so i wish to get a complete example about doing that. i think the other workaround maybe is to make a commandLink being submitted with jquery on the client side and passing parameters through that call but i prefer the former solution

Inject vs ManagedProperty [duplicate]

我只是一个虾纸丫 提交于 2019-12-03 06:47:04
This question already has an answer here: Backing beans (@ManagedBean) or CDI Beans (@Named)? 5 answers Okay, so I have a JSF backing bean that needs a reference to another (@NoneScoped) bean. Should I @Inject it or use @ManagedProperty to obtain an instance reference from the container? Why use one and not the other, in my mind the two approaches achieve the same thing. @ManagedProperty and @NoneScoped comes from the JSF 2.0 spec whilst @Inject comes from the CDI spec. If you are just working on a servlet application that doesn't make any use of any of the others JavaEE 6 features, then go

How to access property of one managed bean in another managed bean

 ̄綄美尐妖づ 提交于 2019-12-03 04:02:48
I have a managed bean (SessionScope as follow) @ManagedBean(name="login") @SessionScoped public class Login implements Serializable { private String userSession; public Login(){ } } In this managedbean, somewhere in the login function, i store the email as a session. I have another managed bean called ChangePassword (ViewScoped). I need to access the value of the email which is stored in the userSession. The reason of doing so is that i need to find out the current userSession(email) before i can complete the change password function. (Need change password for that specific email) How do i do

@ManagedBean(name=“foo”) not available by its name in EL #{foo}

做~自己de王妃 提交于 2019-12-02 13:48:00
问题 I'm trying to use an application scoped bean in JSF2, but for some reason it is always null in my request scoped bean. Here's the code I'm using: The application scoped bean: @ManagedBean(eager=true, name="applicationTracking") @ApplicationScoped public class ApplicationTracking implements Serializable { private static final long serialVersionUID = 4536466449079922778L; public ApplicationTracking() { System.out.println("ApplicationTracking constructed"); } } The request scoped bean:

JBoss 7.1 Weld finds Managed Bean in a jar in the ear, but the war does not

半世苍凉 提交于 2019-12-02 13:10:30
问题 jboss-as-7.1.1, dynamic web module 3.0, JSF 2.0 (Mojarra), Eclipse Indigo sr2 I have an EAR, Ynale.ear, which contains a YnaleImpl.jar and a Ynale.war: Ynale.ear |-YnaleWeb.war | |-META-INF | | |-MANIFEST.MF: | | Manifest-Version: 1.0 | | Class-Path: deployment.Ynale.ear.YnaleImpl | | | |-WEB-INF | | |-beans.xml | | | (empty) | | | | | |-faces-config.xml: | | | <?xml version="1.0" encoding="UTF-8"?> | | | <faces-config version="2.0" | | | xmlns="http://java.sun.com/xml/ns/javaee" | | | xmlns