title: jsf commandbutton action not working ajax
body: <p>I've got this page, I have two forms on. The second form is loaded (rendered) by ajax. The problem is, that when button of the next form is pressed, the page just reloads itself, not actually calling the method specified in 'action'.</p>
  
  <p>XHTML</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                  template="./../WEB-INF/employeeTemplate.xhtml"
                  xmlns:h="http://java.sun.com/jsf/html"
                  xmlns:f="http://java.sun.com/jsf/core"
                  xmlns="http://www.w3.org/1999/xhtml"&gt;
  
      &lt;ui:define name="content"&gt;
          finding user ...
          &lt;h:form id="mainForm"&gt;
              &lt;h:inputText id="userId" value="#{eFindUser.userId}" /&gt;
              &lt;h:commandButton value="Render!" action="#{eFindUser.findUser}" &gt;
                  &lt;f:ajax event="action" execute="userId" render="@all" /&gt;
              &lt;/h:commandButton&gt;
          &lt;/h:form&gt;        
  
          &lt;h:panelGroup id="result"&gt;
              &lt;h:panelGroup layout="block" rendered="#{eFindUser.notFound}" style="color:red"&gt;
                  User not found
              &lt;/h:panelGroup&gt;
  
              &lt;h:form&gt;
                  &lt;h:panelGroup layout="block" rendered="#{eFindUser.responseRendered}" &gt;
  
                      &lt;h:inputHidden value="#{eFindUser.user}" /&gt;
                      &lt;table&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Name&lt;/td&gt; &lt;td&gt;#{eFindUser.user.name}&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;Balance:&lt;/td&gt; &lt;td&gt;#{eFindUser.user.account.balance}&lt;/td&gt;
                          &lt;/tr&gt;
  
                          &lt;tr&gt;
                              &lt;td&gt;&lt;h:commandButton value="update balance" action="#{eFindUser.process()}" /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
  
  
                  &lt;/h:panelGroup&gt;
              &lt;/h:form&gt;                        
          &lt;/h:panelGroup&gt;
  
  
  
      &lt;/ui:define&gt;
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>Backing bean</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package backingbeans;
  
  import entities.User;
  import java.io.Serializable;
  import java.util.Random;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.ViewScoped;
  import javax.inject.Inject;
  import javax.validation.constraints.NotNull;
  import stateless.EmployeeFacade;
  
  /**
   *
   * @author Martin
   */
      @ManagedBean(name="eFindUser")
      @ViewScoped
      public class EFindUserManagedBean implements Serializable{
          private static final long serialVersionUID = -7106162864352727534L;
          private boolean responseRendered = false;
          private boolean notFound = false;
          @NotNull
          private Long userId;
          private User user;
  
          @Inject
          private EUpdateBalanceManagedBean updateBalance;
  
          @Inject
          private EmployeeFacade employeeFacade;
  
          /**
           * Creates a new instance of EFindUserManagedBean
           */
  
          public EFindUserManagedBean() {
          }
  
          public void findUser() {
              if(new Random().nextDouble() &lt; 0.3) {
                  notFound = true;
                  responseRendered = false;
              } else {
                  notFound = false;
                  responseRendered = true;
                  user = employeeFacade.getUserById(3L);
              }
  
          }
          public boolean isResponseRendered() {
              return responseRendered;
          }
  
          public void setResponseRendered(boolean responseRendered) {
              this.responseRendered = responseRendered;
          }
  
      public boolean isNotFound() {
          return notFound;
      }
  
      public void setNotFound(boolean notFound) {
          this.notFound = notFound;
      }
  
      public Long getUserId() {
          return userId;
      }
  
      public void setUserId(Long userId) {
          System.out.println("blah");
          this.userId = userId;
      }
  
      public User getUser() {
          return user;
      }
  
      public void setUser(User user) {
          System.out.println("setting user");
          this.user = user;
      }
  
  
      public String process() {
          updateBalance.setUser(user);
          System.out.println("process");
          return "/employee/updateBalance.xhtml?faces-redirect=true";
      }
  
      }
  </code></pre>
  
  <p>When I click the first 'Render!'-labeled button, it works like charm. Second form is loaded and ready to work. When I click the next 'update balance'-labeled button, the page just reloads which it shouldn't, of course. It should redirect to "/employee/updateBalance". Or it should at least call the process method.</p>
  
  <p>Thanks a lot</p>
  
  <p>EDIT: @BalusC is right, the answer is in previous question</p>