title: using templates in primefaces JSF
body: <p>I have main page index.xhtml with declared place to put content dependent on page clicked.
  </p>
  
  <pre><code>            &lt;br&gt;
              &lt;div id="centerContent"&gt;
          &lt;ui:insert name="centerContent" &gt;
                &lt;ui:param name="mainTag" value="" /&gt;
          &lt;ui:include src="/template/commonContent.xhtml" /&gt;
          &lt;/ui:insert&gt;
                  &lt;h4&gt;#{mainTag}&lt;/h4&gt;
             &lt;/div&gt;
              &lt;/br&gt;&lt;br&gt;&lt;/br&gt;
              &lt;p:panel id="content"&gt;
                          &lt;h:form&gt;
      &lt;h:inputText id="namez" &gt;&lt;/h:inputText&gt;
  &lt;/h:form&gt;
              &lt;/p:panel&gt;       
          &lt;/p:layoutUnit&gt;
  </code></pre>
  
  <p>my template commonContent is:</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:ui="http://java.sun.com/jsf/facelets"
        &gt;
      &lt;body&gt;
          &lt;ui:composition&gt;
          &lt;h1&gt;Ubezpieczamy najlepiej!&lt;/h1&gt;
          &lt;/ui:composition&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and page for sending emails is:</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:body&gt;
  
          &lt;ui:composition template="index.xhtml"&gt;
  
              &lt;ui:define name="centerContent"&gt;
                  &lt;h2&gt;Zapytaj&lt;/h2&gt;
                          &lt;h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Welcome Me"&gt;
              &lt;/h:commandButton&gt;
                          &lt;ui:param name="mainTag" value="Z chęcią odpowiemy" /&gt;
              &lt;/ui:define&gt;
  
  
          &lt;/ui:composition&gt;
  
      &lt;/h:body&gt;
  </code></pre>
  
  <p></p>
  
  <p>when commandButton is put on main pages it works, email is sent, but when loaded via template it didn't work. All things work but not <code>&lt;h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Welcome Me"&gt;</code>. <strong>Why it doesn't work when loaded via clicked template</strong>?</p>
  
  <p>bean code:</p>
  
  <pre><code>import javax.faces.bean.ManagedBean;
  import javax.faces.bean.SessionScoped;
  import javax.mail.*;
  import org.apache.commons.mail.DefaultAuthenticator;
  import org.apache.commons.mail.Email;
  import org.apache.commons.mail.EmailException;
  import org.apache.commons.mail.SimpleEmail;
  
  
  /**
   *
   * @author root
   */
  @ManagedBean
  @SessionScoped
  public class mySendBean {
  
      private myEmailSend mE;
      /**
       * Creates a new instance of mySendBean
       */
      public mySendBean() {
          mE=new myEmailSend();
      }
  
      private static int j;
  
      /**
       * Get the value of j
       *
       * @return the value of j
       */
      public int getJ() {
          return j;
      }
  
      /**
       * Set the value of j
       *
       * @param j new value of j
       */
      public void setJ(int j) {
          this.j = j;
      }
  
          private String name="iop";
  
      /**
       * Get the value of name
       *
       * @return the value of name
       */
      public String getName() {
          return name;
      }
  
      /**
       * Set the value of name
       *
       * @param name new value of name
       */
      public void setName(String name) {
          this.name = name;
          sendMail2();
      }
  
      public String getSayWelcome(){
         //check if null?
         if("".equals(name) || name ==null){
          return "";
         }else{
          return "Ajax message : Welcome " + name;
         }
      }
  
      public void setSendMail(){
          sendMail2();
      }
      public void sendMail2(){ 
          j=getJ();
          setJ(++j);
  
          Email email = new SimpleEmail();
          try {
          //send mail
      }
  }
  </code></pre>