title: JSF ajax event does not work in form
body: <p>Yesterday I created a really simple JSF project to practice how to render a dynamic menu with Ajax request.
  The addition method works pretty well, but in case I switch to another tab the result is not calculated and displayed in the page.
  I debugged the code for hours, but till yet I haven't found the root cause. Do you have any idea what the problem can be?</p>
  
  <p>Web Pages</p>
  
  <p>index.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://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:f="http://xmlns.jcp.org/jsf/core"&gt;
  &lt;h:head&gt;
      &lt;title&gt;Mathematics&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;h:panelGroup id="menu"&gt;
          &lt;h:form&gt;
              &lt;f:ajax render="page"&gt;
                  &lt;h:commandButton value="Addition" action="#{menuMB.setPage('addition')}"&gt;&lt;/h:commandButton&gt;
                  &lt;h:commandButton value="Subtraction" action="#{menuMB.setPage('subtraction')}"&gt;&lt;/h:commandButton&gt;
                  &lt;h:commandButton value="Multiplication" action="#{menuMB.setPage('multiplication')}"&gt;&lt;/h:commandButton&gt;
                  &lt;h:commandButton value="Division" action="#{menuMB.setPage('division')}"&gt;&lt;/h:commandButton&gt;
              &lt;/f:ajax&gt;
          &lt;/h:form&gt;
      &lt;/h:panelGroup&gt;
      &lt;h:panelGroup id="page"&gt;
          &lt;ui:include src="/WEB-INF/includes/#{menuMB.page}.xhtml"/&gt;
      &lt;/h:panelGroup&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>addition.xhtml</p>
  
  <pre><code>&lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://xmlns.jcp.org/jsf/html"
              xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  &lt;h:panelGroup id="header"&gt;
      &lt;h1&gt;Addition&lt;/h1&gt;
  &lt;/h:panelGroup&gt;
  &lt;h:panelGroup id="content"&gt;
      &lt;h:form id="addition"&gt;
          &lt;h:outputLabel for="number1" value="Number1:"/&gt;
          &lt;h:inputText id="number1" value="#{mathMB.number1}"&gt;
              &lt;f:ajax event="keyup" listener="#{mathMB.addition}" execute="number1 number2" render="result"/&gt;
          &lt;/h:inputText&gt;
          &lt;h:outputLabel for="number2" value="Number2:"/&gt;
          &lt;h:inputText id="number2" value="#{mathMB.number2}"&gt;
              &lt;f:ajax event="keyup" listener="#{mathMB.addition}" execute="number1 number2" render="result"/&gt;
          &lt;/h:inputText&gt;
          &lt;h:outputLabel for="result" value="Result:"/&gt;
          &lt;h:outputText id="result" value="#{mathMB.result}"/&gt;
      &lt;/h:form&gt;
  &lt;/h:panelGroup&gt;
  </code></pre>
  
  <p></p>
  
  <p>All other xhtml pages (division, multiplication, subtraction) are the same as above, only the addition method is changed with the proper one.</p>
  
  <p>Managed Beans</p>
  
  <p>MathMB</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class MathMB {
  
      private Integer number1;
      private Integer number2;
      private Integer result;
  
      public void addition() {
          if (number1 == null || number2 == null) {
              return;
          }
          result = number1 + number2;
      }
  
      subtraction...
      multiplication...
      division...
  
      //getters + setters
  }
  </code></pre>
  
  <p>MenuMB</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class MenuMB implements Serializable {
  
      private String page;
  
      @PostConstruct
      public void init() {
          page = "addition";
      }
  
      public String getPage() {
          return page;
      }
  
      public void setPage(String page) {
          this.page = page;
      }
  }
  </code></pre>
  
  <p>Thanks a lot for any tips!</p>