Hi Joe, On Mon, 2009-04-06 at 13:31 -0500, Knudsen, Joe wrote: > Can a valueChangeListener be called twice? I am using both a binding= > and a value= on a h:selectOneMenu, and the valueChangeListener gets > called twice. Wonder if that is an issue with MyFaces I am using > version 1.2.5. I think I can refactor out the binding statement or I > could add logic to look for the multiple calling. Any ideas? > >
A valueChangeListener should only be called once. During the "process values" phase of a request, each component in the tree is told to check the submitted form. The component looks for a submitted value with id equal to the component clientId. It then runs its converters (if any) and its validators (if any). Then it reads the property it is bound to (via the "value" attribute on the component), and if that is different from the value it just got from the form (after conversion) then it queues a ValueChangeEvent for later processing. Each component is told to do the above just once per request, so it will queue at most one ValueChangeEvent. So I don't know why you would be getting two callbacks. Do be careful with bindings. A binding should NEVER be used to bind a component to anything except a request-scoped backing bean. Well, you can do it if you explicitly clear the property at the end of each request, but that's often not easy to do. In general, avoid binding completely wherever possible. I suppose that if somehow due to bad bindings, there were two components with the same id in the component tree, then both of them would do the above processing, and so two change events would be generated. Not sure if it is possible to get that scenario, but definitely something to check... I would first try checking for duplicated components in the tree; just walk the tree starting from the UIViewRoot, and check whether your problem component is in the tree twice. You could also put a breakpoint in the myfaces code and see what ValueChangeEvents are being registered (see UIViewRoot.queueEvent). Regards, Simon

