Reputation: 455
My valueChangeListener for SelectOneChoice is not getting invoked when I am trying to select a value in the dropdown. It is invoked only when I click on the Blank Item in the dropdown (which we configure in ListOfValues). On some research I have learnt that in your valueChangeListener, we must add
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
as our first line. But It is still not getting invoked on selection of any other value apart from null.
Code for my SelectOneChoice
<af:selectOneChoice value="#{bindings.Prefix.inputValue}"
label="#{bindings.Prefix.label}"
shortDesc="#{bindings.Prefix.hints.tooltip}"
id="soc3"
partialTriggers="formatIdId"
visible="#{bindings.Prefix.hints.visible}"
binding="#{backingBeanScope.CreateItemBackingBean.prefixField}"
required="#{bindings.ItemNumberType.attributeValue eq 'VPLU'}"
showRequired="#{bindings.Prefix.hints.mandatory}"
validator="#{backingBeanScope.CreateItemBackingBean.onValidatePrefix}"
autoSubmit="true"
valueChangeListener="#{backingBeanScope.CreateItemBackingBean.onChangePrefix}">
<f:selectItems value="#{bindings.Prefix.items}" id="si3"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.Prefix.format}"/>
</af:selectOneChoice>
Code for my ValueChangeListener
public void onChangePrefix(ValueChangeEvent vce) {
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
System.out.println("vce.getOldValue()"+vce.getOldValue());
System.out.println("vce.getNewValue()"+vce.getNewValue());
System.out.println("I am in changed prefix");
}
Upvotes: 0
Views: 13391
Reputation: 1657
It may be your required tag preventing the valueChangeListener from firing.
required="#{bindings.ItemNumberType.attributeValue eq 'VPLU'}"
If "required" returns true, valueChangeListener won't be executed. Also, remove "showRequired" attribute completely. Is not only not necessary, but is confusing because it has a different condition than "required" attribute.
Try a bit of debugging and set required="false".You can also remove "validator", "visible", see if it works without them, then add them back one by one.
Upvotes: 2
Reputation: 1804
valueChangeListener
will fire only when you submit form. You can use any submit action for it or just turn on autosubmit
property on component.
If you need to catch selection event without actually submitting data, you should use clientListener
and handle it with javascript functions.
Upvotes: 2