title: Regarding communication between managed bean in JSF
body: <p>It seems I am not clear on my previous question about managed bean. So, I am posting it again in a more systematic manner.</p>
  
  <p>I have one page:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Facelet Title&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;ui:insert name="head"&gt;
  
          &lt;/ui:insert&gt;
  
          &lt;br/&gt;&lt;br/&gt;
          &lt;h:inputText value="#{MasterBean.laala}"/&gt;
          &lt;br/&gt;&lt;br/&gt;
  
          &lt;ui:insert name="content"&gt;
  
          &lt;/ui:insert&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is its bean:</p>
  
  <pre><code>import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  
  
  @ManagedBean(name="MasterBean")
  @ViewScoped
  public class MasterBean {
  
      private String laala;
  
      public String getLaala() {
          return laala;
      }
  
      public void setLaala(String laala) {
          this.laala = laala;
      }
  
  
      public MasterBean() {
      }
  
  }
  </code></pre>
  
  <p>This is data.xhtml which uses master.xhtml:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
      &lt;h:head&gt;
          &lt;title&gt;Facelet Title&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;ui:composition template="master.xhtml"&gt;
              &lt;ui:define name="head"&gt;
                  laala
              &lt;/ui:define&gt;
  
              &lt;h:outputText value="#{pageBean.content}"/&gt;
  
              &lt;ui:define name="content"&gt;
                  &lt;h:commandButton actionListener="#{pageBean.speakHello}"/&gt;
              &lt;/ui:define&gt;&gt;
  
  
          &lt;/ui:composition&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is its bean:</p>
  
  <pre><code>import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  
  
  @ManagedBean(name="pageBean")
  @ViewScoped
  public class pageBean {
  
      private String content;
  
      public String getContent() {
          return content;
      }
  
      public void setContent(String content) {
          this.content = content;
      }
  
  
      public void speakHello(){
          //how do i get value of laaala here which is in MasterBean???
          content = ??? + " Hello friend";
      }
  
      public pageBean() {
      }
  
  }
  </code></pre>
  
  <p>What should I put in the blank where <code>???</code> is marked in speakHello(). How do I get value of other bean in this bean?</p>