views:

403

answers:

1

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)

+1  A: 

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.

BalusC
BalusC thanks so much for all the help. You've really helped me increase my understanding of JSF.I'm not sure what you mean by in the bean's action method. I'm using partial submits in icefaces and I can't see how to change the date in the selectInputDate given a change in the selectOneMenu. Appreciate your help.
DD
"Partial submits" are asynchronous (ajax) submits. You didn't mention about it in the question. That would change things. But to the point, the `update model values` phase which occurs after the `validations phase` (wherein the `valueChangeListener` get invoked) has overriden the value you've manually set. In your case I think just calling `FacesContext#responseComplete()` is sufficient.
BalusC
Should I be using valueChangeListener to do this?
DD
I don't know what the possibilities of `partialSubmit` are (I don't do IceFaces), but if there's no other way, then go ahead with it and call `FacesContext#responseComplete()`.
BalusC
after responseComplete it doesnt render the new values..I tried renderReposne instead and this works fine except when I reset the values to null the calendar doesnt clear for some reason.how would you do it without partial submits? Basically if dateRange=custom in the selectOneMenu I want to set the Date to now in the selectInputDate...otherwise set the date to null.
DD
My bad, I indeed mean to call `FacesContext#renderResponse()`. I am not sure if I understand the problem of it not working when you set it to null instead of now.
BalusC