Managed bean communication
Until now, we have focused especially on the communication between Facelets and managed beans. In this section, we will cover another important aspect regarding JSF communication—managed beans communication. We will discuss the following topics:
- Injecting a managed bean into another bean
- Communication between managed beans using the application/session map
- Accessing other managed beans programmatically
Injecting a managed bean into another bean
A managed bean can be injected into another managed bean using @ManagedProperty
. For example, let's suppose that you have a managed bean in the session scope that stores a player name and surname, as shown in the following code:
@Named @SessionScoped public class PlayersBean implements Serializable{ private String playerName; private String playerSurname; public PlayersBean() { playerName = "Rafael"; playerSurname = "Nadal"; } //getters and setters }
Now, let's suppose that...