title: Set Focus for Primefaces Component in Bean with WidgetVar with RequestContex Execute
body: <p>Is there a way to set my component focus after an function call to an other component with Primefaces RequestContex?</p>
  
  <p>i tried:</p>
  
  <pre><code>RequestContex.getCurrentInstance().execute("PF('WidgetVar').focus();");
  </code></pre>
  
  <p>and</p>
  
  <pre><code>RequestContex.getCurrentInstance().execute("(((InputText) event.getComponent()).getWidgetVar()).focus();");
  </code></pre>
  
  <p>I dont get an error but nothing happens.</p>
  
  <p>Did i miss something or is this not possible?</p>
  
  <p>I use Primefaces 4.0.3 and MyFaces 2.0.2</p>
  
  <p><strong>EDIT</strong> Example Code</p>
  
  <p><em>Bean</em></p>
  
  <pre><code>import java.io.Serializable;
  import java.util.logging.Logger;
  
  import javax.annotation.PostConstruct;
  
  import org.primefaces.context.RequestContext;
  
  public class NavigationBean implements Serializable {
  
      private static final long serialVersionUID = 1L;
      private String input;
  
      public NavigationBean() {}
  
      @PostConstruct
      public void init() {
  
      }
  
      public void goNext() {
          Logger.getAnonymousLogger().warning("GONEXT");
          RequestContext.getCurrentInstance().scrollTo("w3");
  
      }
  
      public String getInput() {
          return input;
      }
  
      public void setInput(String input) {
          this.input = input;
      }
  
  }
  </code></pre>
  
  <p>XHTML</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 xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"&gt;
  &lt;h:head&gt;
  
  
  &lt;/h:head&gt;
  
  &lt;h:body &gt;
  
  &lt;h:form id="form"&gt;
  &lt;h:inputText id="input1" value="#{navigationBean.input}" widgetVar="w1"&gt;&lt;/h:inputText&gt;
  &lt;h:inputText id="input2" value="#{navigationBean.input}" widgetVar="w2"&gt;&lt;/h:inputText&gt;
  &lt;h:inputText id="input3" value="#{navigationBean.input}" widgetVar="w3"&gt;&lt;/h:inputText&gt;
  &lt;h:inputText id="input4" value="#{navigationBean.input}" widgetVar="w4"&gt;&lt;/h:inputText&gt;
      &lt;p:commandButton value="focus" action="#{navigationBean.goNext()}" /&gt;
  
  &lt;/h:form&gt;
  
  
  &lt;/h:body&gt;
  
  &lt;/html&gt;
  </code></pre>