Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

valuechangelistener - getoldvalue() does not work fine, always returns the same  RSS feed

 
Men rai
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with valuechangelistener associated to a selectOneMenu.
The problem is that the value returned by the getOldValue() function is always the same, if the variable associated is not initialized is always 0. If the variable in the backing bean is initialized the getOldValue always return the initial value.
The getNewValue function works fine.
Does anybody why the getOldValue functions does not work??
What I want to do is to update a data list when the value of the selectOneMenu is changed.
The code is as follows:

The code in the xhtml:

<h:selectOneMenu id="validacio" value="#{Testback.validacio}" valueChangeListener="#{Testback.ListenerValidacio}" onchange="this.form.submit()" >
<f:selectItem itemLabel="1" itemValue="1"></f:selectItem>
<f:selectItem itemLabel="2" itemValue="2"></f:selectItem>
<f:selectItem itemLabel="3" itemValue="3"></f:selectItem>
<f:selectItem itemLabel="4" itemValue="4"></f:selectItem>
<f:selectItem itemLabel="5" itemValue="5"></f:selectItem>
<f:selectItem itemLabel="6" itemValue="6"></f:selectItem>
<f:selectItem itemLabel="7" itemValue="7"></f:selectItem>
</h:selectOneMenu>

The code in the backing bean:

int validacio;

public void ListenerValidacio(ValueChangeEvent vce) {
setValidacio((Integer) vce.getNewValue());
System.out.println("validacio: " + validacio);
System.out.println("Testback - ListenerValidacio - new: " + vce.getNewValue() + " - old: " + vce.getOldValue());
}

The output of the log while changing the values in the selectOneMenu:

INFO: validacio: 1
INFO: Testback - ListenerValidacio - new: 1 - old: 0
INFO: validacio: 2
INFO: Testback - ListenerValidacio - new: 2 - old: 0
INFO: validacio: 5
INFO: Testback - ListenerValidacio - new: 5 - old: 0
INFO: validacio: 2
INFO: Testback - ListenerValidacio - new: 2 - old: 0

It happens the same with another listener in the same page, the oldvalue is always false, is a selectBooleanCheckbox.

Thanks in advance.

 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hmmm, I notice that I've never tried to use getOldValue(), although I see it in my IDE autocomplete
list almost every day. I mean you have to use getNewValue() because the new value hasn't been
written into the backing bean pre validation phase for obvious reasons. But if you have an old
value, it must be somewhere, so get it from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!