DataModelListener is not notified the very first time the UIData's row index
changes from -1 to 0
-------------------------------------------------------------------------------------------------
Key: MYFACES-3388
URL: https://issues.apache.org/jira/browse/MYFACES-3388
Project: MyFaces Core
Issue Type: Bug
Components: General
Affects Versions: 2.1.3
Reporter: Jesús Pérez Alcaide (ISBAN)
Priority: Minor
I'm writing a custom version of UIData component by extending the default
UIData class. I want to register a DataModelListener in order to be notified on
UIData's row index changes.
I have overridden the UIData#setValue(Object) method to register a
DataModelListener whenever a new value is set to the component:
@Override
public void setValue(Object value) {
super.setValue(value);
getDataModel().addDataModelListener(new MyDataModelListener());
}
But MyDataModelListener is not notified the very first time the UIData's row
index changes from -1 to 0.
Looking through the code, this is caused because when getDataModel() is first
called, it calls createDataModel() and then a new model instance is created
using the one-argument constructor. This one-argument constructor in all
variants of DataModel concrete classes calls the method setWrappedData() and,
as the specification of this method says:
"If data is non-null, the currently selected row index must be
set to zero, and a DataModelEvent must be sent to the rowSelected() method of
all registered DataModelListeners indicating that this row is now selected."
But this DataModelEvent will never be sent to any listeners, because this is
triggered from the constructor and so, it is impossible to have any listener
registered.
This issue has a very easy workaround, to reset the model's row index right
after its creation.
@Override
public void setValue(Object value) {
super.setValue(value);
DataModel<?> dm = getDataModel();
dm.setRowIndex(-1); // FIXME reset rowIndex due to bug
dm.addDataModelListener(new MyDataModelListener());
}
I think that one solution may be that the one-argument constructor of the
DataModel classes shouldn't call setWrappedData(), but instead assign its
internal variable directly.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira