Using PF 5.1, JSF 2.2.7 on Glassfish 4.1.
I have this simple example with a 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>
Bean:
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");
}
}
It works as expected, except that if the dropdown has focus and I press ALT on windows or CMD on mac it will call the listener and also reset the dropdown. This happens when the dropdown is not at its default value (when its already on 2 or 3). And this means I cannot for example press ALT + TAB to check something in another open program - when I come back it will be reset.
Why this wicked behaviour and how to avoid it? I would rather not have a press on ALT to fire an event="change"
and reset the component.