jsficefaces

JSF Problem with selectInputDate overriding a set value


I have a problem with selectInputDate: I have a backing bean which I am binding to the selectInputDate. I have a menu which, when the menu changes, I set the date to now to the same property the selectInputDate is bound to.

For some reason, the date changes correctly, but the selectInputDate then calls a set and overrides the value with the old value...

Any idea why selectInputDate would call the setter?

<ice:selectInputDate popupDateFormat="dd-MMM-yyyy" renderAsPopup="true" value="#{dateContoller.date}"/>

<ice:selectOneMenu value="#{dateContoller.dateRange}" valueChangeListener="#{dateRangeDateContoller.dateRangeChanged}"  >
....
</ice:selectOneMenu> 

(dateRangeChanged sets the current date to now)


Solution

  • The valueChangeListener is intend to run some code logic whenever the newly submitted value differs from the original value. But you're apparently actually not interested in the change of the value, you're actually interested in resetting the submitted value.

    Just get rid of the valueChangeListener and do your thing in the bean's action method.

    If that is not an option for some reason, then you need to elaborate more about the problem for which you thought that using a valueChangeListener is the right solution. There may be workarounds to keep the valueChangeListener anyway, such as calling FacesContext#renderResponse(), so that JSF won't run the update model values (and invoke action!) phases anymore, or using ValueChangeEvent#queue() to let it re-execute itself during invoke action phase.

    To learn a bit more about the JSF lifecycle and when/why/how the one and other get called/invoked, you may find this practical article useful.