I'm facing a issue where on changing rich:comboBox value, i need to call backing bean. So i'm using valueChangeListener with a4j:support event="onchange" as bellow:
<rich:comboBox value="#{myBean.name}" defaultLabel="#{messages['dropdown.defaultText']}" label="#{messages['label.name']}" status="defaultStatus" valueChangeListener="#{myBean.checkToChangeName}" disabled="#{myBean.isAdminUser}" >
<f:selectItems value="#{myBean.nameList}" />
<a4j:support event="onchange" reRender="errTable,popUpPanel" oncomplete="if(#{myBean.showPopup}) #{rich:component('popUpPanel')}.show();" />
</rich:comboBox>
The backing bean method:
public boolean checkToChangeName(ValueChangeEvent event){
// Code to check change is valid & its impact on other fields
}
The method checkToChangeName() should get call only on change event. But in my case, the methods is getting called on change event & also getting called on submit of the form which i don't need & creating trouble.
I'm using h:commandButton as bellow to submit the form:
<h:commandButton id="btnSave" value="#{messages['action.save']}" action="#{myBean.updateProfile}" reRender="profileForm" />
Can anyone help me to understand why its calling checkToChangeName() method on submit? & How can i prevent it?
I got the issue. The whole form was getting re-render on save which was causing call to
valueChangeEventListener
. To avoid this, I just changed belowreRender
attibute for savecommandButton
:Old:
New:
Now the problem is resolved.