I have spent quite some time on something that (to me) looks like a bug in PrimeFaces. I have now narrowed it down to a simple example -- I hope that it can be of use in fixing the bug.
Here is my example:
DropDownBean.java (DDB):
Code: Select all
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;
@ManagedBean(name = "DDB")
@ViewScoped
public class DropDownBean implements Serializable
{
private static final long serialVersionUID = 7735251946389945740L;
public List<SelectItem> getValues()
{
List<SelectItem> res = new ArrayList<SelectItem>();
res.add(new SelectItem("1", "A"));
res.add(new SelectItem("2", "B"));
res.add(new SelectItem("3", "C"));
res.add(new SelectItem("4", "D"));
return res;
}
public String getInitValue()
{
return "2";
}
public void valueChanged()
{
System.out.println("!!!CHANGED!!!");
}
}
dd1.xhtml:
Code: Select all
<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>
<f:view>
<h:form>
<p:selectOneMenu value="#{DDB.initValue}" effect="fade" effectDuration="100">
<f:selectItems value="#{DDB.values}" />
<p:ajax listener="#{DDB.valueChanged}" event="change" />
</p:selectOneMenu>
</h:form>
</f:view>
</h:body>
</html>
I then copied "dd1.html" to "dd2.html" and removed the "value" attribute the from <p:selectOneItem> element. Here's the source code for dd2.xhtml:
Code: Select all
<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>
<f:view>
<h:form>
<p:selectOneMenu effect="fade" effectDuration="100">
<f:selectItems value="#{DDB.values}" />
<p:ajax listener="#{DDB.valueChanged}" event="change" />
</p:selectOneMenu>
</h:form>
</f:view>
</h:body>
</html>
In my application, I need to be able to set the initial value of <p:selectOneMenu> and at the same time I need to trigger an AJAX request whenever the value is changed. Unfortunately, I cannot get the two things to work at the same time. To me, this looks like a bug in PrimeFaces. Has anyone else seen this problem? Is there a workaround?
Best regards,
Mads
BTW: I have used the PrimeFaces version from SVN (I built it yesterday) with Mojarra 2.1.3. I have also tried with a version that I built from SVN a month ago, and here I get the same problem.