Setzen Sie den Fokus für die Primefaces-Komponente in Bean mit WidgetVar mit RequestContex Execute
Gibt es eine Möglichkeit, meinen Komponentenfokus nach einem Funktionsaufruf einer anderen Komponente mit Primefaces RequestContex zu setzen?
Ich habe es versucht:
RequestContex.getCurrentInstance().execute("PF('WidgetVar').focus();");
und
RequestContex.getCurrentInstance().execute("(((InputText) event.getComponent()).getWidgetVar()).focus();");
Ich bekomme keine Fehlermeldung, aber es passiert nichts.
Habe ich etwas verpasst oder ist das nicht möglich?
Ich benutze Primefaces 4.0.3 und MyFaces 2.0.2
BEARBEITEN Beispielcode
Bohne
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;
}
}
XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<h:head>
</h:head>
<h:body >
<h:form id="form">
<h:inputText id="input1" value="#{navigationBean.input}" widgetVar="w1"></h:inputText>
<h:inputText id="input2" value="#{navigationBean.input}" widgetVar="w2"></h:inputText>
<h:inputText id="input3" value="#{navigationBean.input}" widgetVar="w3"></h:inputText>
<h:inputText id="input4" value="#{navigationBean.input}" widgetVar="w4"></h:inputText>
<p:commandButton value="focus" action="#{navigationBean.goNext()}" />
</h:form>
</h:body>
</html>