0

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?

Saurabhcdt
  • 1,010
  • 1
  • 12
  • 24
  • The change triggers when the component loses focus, are you submitting right after you change the value? – Makhiel Jun 02 '14 at 11:38
  • Some times submit is clicked just after change in any of the combo box on the screen but not every time. But in both cases, the event gets triggered. Is there any way to stop this behavior? – Saurabhcdt Jun 04 '14 at 06:47

1 Answers1

0

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 below reRender attibute for save commandButton:

Old:

<h:commandButton id="btnSave" value="#{messages['action.save']}"
                 action="#{myBean.updateProfile}" reRender="profileForm" />

New:

<h:commandButton id="btnSave" value="#{messages['action.save']}"
                 action="#{myBean.updateProfile}" reRender="errorMessageTable" />

Now the problem is resolved.

Saurabhcdt
  • 1,010
  • 1
  • 12
  • 24