Glassfish 4.1 で PF 5.1、JSF 2.2.7 を使用。
私はこの簡単な例を次のように持っていますselectOneMenu
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Test</title>
</h:head>
<h:body>
<h:form>
<p:selectOneMenu value="#{testBean.text}">
<p:ajax listener="#{testBean.test()}" update="outputpanel"/>
<f:selectItem itemLabel="1" itemValue="1"/>
<f:selectItem itemLabel="2" itemValue="2"/>
<f:selectItem itemLabel="3" itemValue="3"/>
</p:selectOneMenu>
<p:outputPanel id="outputpanel">
#{testBean.text}
</p:outputPanel>
</h:form>
</h:body>
</html>
豆:
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
@Named
@ViewScoped
public class TestBean implements Serializable
{
private String text;
public String getText() {
return text;
}
public void setText(String text) {
System.out.println("settext: " + text);
this.text = text;
}
public void test() {
System.out.println("test called");
}
}
期待どおりに動作しますが、ドロップダウンにフォーカスがあり、Windows で ALT を押すか、Mac で CMD を押すと、リスナーが呼び出され、ドロップダウンもリセットされます。これは、ドロップダウンがデフォルト値でない場合 (すでに 2 または 3 になっている場合) に発生します。そして、これは、たとえば ALT + TAB を押して、別の開いているプログラムで何かをチェックすることができないことを意味します-戻ったときにリセットされます.
この邪悪な振る舞いの理由とそれを回避する方法は? event="change"
コンポーネントを起動してリセットするために ALT を押したくありません。