title: How to make Command button work outside the form in JSF 2.0
body: <p>I'm beginner in JSF programming, so I have a simple question.</p>
  
  <p>I have the following jsf file:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  
  &lt;h:head&gt;
      &lt;title&gt;Insert Title Here&lt;/title&gt;
  &lt;/h:head&gt;
  
  &lt;body&gt;
      &lt;h:form&gt;
          &lt;h:panelGrid columns="3"&gt;
  
              /* Here I take the username */
  
              &lt;h:outputLabel for="username"&gt;Username&lt;/h:outputLabel&gt;
              &lt;h:inputText id="username" value="#{register.user.username}"  
                  required="true" requiredMessage="Enter username"&gt;
                  &lt;f:ajax event="blur" render="usernameMessage" /&gt;
              &lt;/h:inputText&gt;
              &lt;h:message id="usernameMessage" for="username" /&gt;
  
              /* Here I take the password */
  
              &lt;h:outputLabel for="password"&gt;Password&lt;/h:outputLabel&gt;
              &lt;h:inputSecret id="password" value="#{register.user.password}"
                  required="true" redisplay="true" requiredMessage="Enter password"&gt;
                  &lt;f:ajax event="blur" render="passwordMessage" /&gt;
              &lt;/h:inputSecret&gt;
              &lt;h:message id="passwordMessage" for="password" /&gt;
  
              /* Here I take the email */
  
              &lt;h:outputLabel for="email"&gt;Email&lt;/h:outputLabel&gt;
              &lt;h:inputText id="email" value="#{register.user.email}"
                  required="true" requiredMessage="Enter email"&gt;
                  &lt;f:ajax event="blur" render="emailMessage" /&gt;
              &lt;/h:inputText&gt;
              &lt;h:message id="emailMessage" for="email" /&gt;
  
              /* And these are my 3 command buttons, and they are working only when the username, password and email are filled in. */
  
              &lt;h:panelGroup&gt;
                  &lt;h:commandButton value="Register" action="#{register.submit}"&gt;
                      &lt;f:ajax execute="@form" render="@form" /&gt;
                  &lt;/h:commandButton&gt;
                  &lt;h:commandButton value="setDB" action="#{register.setDB}"&gt;
                      &lt;f:ajax execute="@form" render="@form" /&gt;
                  &lt;/h:commandButton&gt;
                  &lt;h:commandButton value="getDB" action="#{register.getDB}"&gt;
                      &lt;f:ajax execute="@form" render="@form" /&gt;
                  &lt;/h:commandButton&gt;
                  &lt;h:commandButton value="reset" action="#{register.reset}"&gt;
                      &lt;f:ajax execute="@form" render="@form" /&gt;
                  &lt;/h:commandButton&gt;
              &lt;/h:panelGroup&gt;
  
              &lt;h:messages globalOnly="true" layout="table" /&gt;
          &lt;/h:panelGrid&gt;
      &lt;/h:form&gt;
  
      /* And this is the button that I want to work without the need to fill in the username, password and email */
  
      &lt;h:panelGroup rendered="#{register.user.ini!=true}"&gt;
          &lt;h3&gt;Result&lt;/h3&gt;
          &lt;h:commandButton value="getDB" action="#{register.getDB}" /&gt;
      &lt;/h:panelGroup&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So my question is how to make the following command button to work:</p>
  
  <pre><code>&lt;h:panelGroup rendered="#{register.user.ini!=true}"&gt;
      &lt;h3&gt;Result&lt;/h3&gt;
      &lt;h:commandButton value="getDB" action="#{register.getDB}" /&gt;
  &lt;/h:panelGroup&gt;
  </code></pre>
  
  <p>It doesn't appear when I start the application. I just want to get database information without the need to fill the fields in :) ... the other buttons are in the form and they work only when the field's username, password and email have something inside. This code produces neither an exception nor an error, but the button doesn't work (the one that is outside the form).</p>