I've got a problem with PrimeFaces. Here is my XHTML code :
<p:selectOneMenu value="#{gCnewObjectBean.grille.branche}"
valueChangeListener="#{gCnewObjectBean.brancheChangedListener}"
update=":contentform :popup">
<f:selectItems value="#{gCnewObjectBean.branche}" />
<p:ajax update=":contentform :popup"
listener="#{gCnewObjectBean.brancheChangedListener}" />
</p:selectOneMenu>
And here is my bean code :
public void brancheChangedListener(ValueChangeEvent event) {
Integer branche = (Integer) event.getNewValue();
// do populate the second select menu based on this value
}
public void brancheChangedListener(AjaxBehaviorEvent event) {
SelectOneMenu selectMenu = (SelectOneMenu) event.getSource();
Integer branche = (Integer) selectMenu.getSubmittedValue();
// do populate the second select menu based on this value
}
The HTML code generated is a bit strange with primefaces, the HTML select component is hidden. But if I see it with firebug, it looks like this :
<select id="branche_input" name="branche_input">
<option value="0"></option>
<option value="1">Prestations prévoyance professionnelle</option>
<option value="2">Prestations prévoyance privée</option>
<option value="3">Prestations PRIRENT</option>
<option value="4">Gestion prévoyance professionnelle</option>
</select>
This code is a way to test the two solutions (valueChangeListener
and the f:ajax
) described by BalusC on this post.
When I do change the value in the select menu, both listener are triggered, first the valueChangeEvent
, then the AjaxBehaviorEvent
, which is perfectly what I suspected based on BalusC post. But both bean method do get a "null" for the new value (with debugger, I can see that the old value in the ValueChangeEvent
is "0", which is correct according to my selectItems).
Any clue to solve this ? I really dont get it, I saw the code I'm using several time on this site...
Technical info : JBoss EAP 6.0, Mojarra 2.1.7-jboss, PrimeFaces 4.0
Edit : I was wondering if it was a bug in the jsf-impl library embedded in JBoss. I updated to Mojarra 2.1.18-jboss, but the problem is strictly the same : a null
value is placed into my grille
object by the ajax listener and a null
value is also returned by the getNewValue()
object of the valueChangeEvent
.