title: Programmatically control which components should be ajax-updated
body: <p>I have a complex form where the user fills a few fields, and has two options: generate a license file or save the changes. If the user clicks on the generate license file button without saving the changes, I render a small component with an error message asking him to save before generating the license.
  To display the component with a warning message, I want to use ajax to avoid rendering the whole page just to render the warning component. Of course, if the changes were saved, then the warning message is not required and I redirect the user to another page. 
  I have a change listener on the changeable fields to detect when a change has been made. What I don't know is the <strong>conditional execution</strong>. The "render with ajax if unsaved OR redirect if saved" part. Here's the logic</p>
  
  <pre><code>if(saved){
    redirect();
  }else{
    ajax.renderWarning()
  }
  </code></pre>
  
  <p>--EDIT--
  I'm going to add more info because I realized I'm leaving things too open ended. 
  Here's one example of an updateable field.</p>
  
  <pre><code>&lt;h:inputText name="computername3"  value="#{agreement.licenseServerBeans[2].computerId}" valueChangeListener="#{agreement.fieldChange}"&gt;
      &lt;rich:placeholder value="Add Computer ID"/&gt;
  &lt;/h:inputText&gt;
  </code></pre>
  
  <p>The fieldChange() bean method</p>
  
  <pre><code>public void fieldChange(ValueChangeEvent event) {   
     change = true; //change is a boolean, obviously :P
  }
  </code></pre>
  
  <p>Here's the generate license button jsf</p>
  
  <pre><code>&lt;h:commandLink action="#{agreement.generateLicenseFile}"&gt;
      &lt;span class="pnx-btn-txt"&gt;
          &lt;h:outputText value="Generate License File" escape="false" /&gt;
      &lt;/span&gt;
  &lt;/h:commandLink&gt;
  </code></pre>
  
  <p>Here's the generateLicenseFile() method</p>
  
  <pre><code>public String generateLicenseFile(){
      ....//lots of logic stuff
      return "/licenseGenerated.xhtml?faces-redirect=true";
  }
  </code></pre>