title: Redirecting to an external URL in a new tab and performing an action in backing bean at the same time
body: <p>I'm working at a jsf application that at a certain time need to open an external page in a new tab, leaving the first page active. I need to find a way to make the application perform, in a single button click: </p>
  
  <ol>
  <li>a redirect to an external URL in a new tab </li>
  <li>an action which disables the button itself in the original page</li>
  </ol>
  
  <p>I've tried using an <code>&lt;outputLink /&gt;</code> but it has no action attribute. 
  I've tried using a <code>&lt;commandLink /&gt;</code>but it's unable to redirect outside.
  I've also tried a <code>&lt;commandLink /&gt;</code> with <code>target="_blank"</code> and a redirection coded in the backing bean:</p>
  
  <pre><code>&lt;h:commandLink onclick="submit();" target="_blank" action="#{myBean.execute}" disabled="#{myBean.linkDisabled}" value="external link" /&gt;
  </code></pre>
  
  <p>and, in the backing bean:</p>
  
  <pre><code>public String execute() {
      linkDisabled = true;
  
      try{
          ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
          externalContext.redirect(Constants.EXTERNAL_URL);
      } catch(Exception e){
          throw new FacesException("Redirection failed");
      }
  
      return THIS_PAGE;
  }
  </code></pre>
  
  <p>A page is opened in a new tab but it's the current page instead of the that with URL <code>Constants.EXTERNAL_URL</code>and the button is still enabled. No error message is shown. Any suggestion?</p>
  
  <p>Thanks in advance, Andrea</p>