Hello,
I think I have found a bug, but rather than open an issue I prefer to ask it
here first.
I'm writing a custom version of UIData component extending the default UIData
class. I want to register a DataModelListener in order to be notified on row
index changes.
I have overridden the setValue(Object) method to register the 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 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 say the
specification of this method:
"If data is non-null, the currently selected row index must be
set to zero, and a
DataModelEvent<http://javaserverfaces.java.net/nonav/docs/2.1/javadocs/javax/faces/model/DataModelEvent.html>
must be sent to the rowSelected() method of all registered
DataModelListener<http://javaserverfaces.java.net/nonav/docs/2.1/javadocs/javax/faces/model/DataModelListener.html>s
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.
So, I have had to refactor my code to workaround this bug, this way:
@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());
}
To solve this, and to be compliant with the spec, I think that the one-argument
constructor of the DataModel classes shouldn't call setWrappedData(), but
instead assign its internal variable directly.
What do you think?
Un saludo,
Jesús Pérez Alcaide
Lab. Banksphere - Runtime
Tlf: 91 470 5223
*********************AVISO LEGAL **********************
Este mensaje es privado y confidencial y solamente para la persona a la que va
dirigido. Si usted ha recibido este mensaje por error, no debe revelar, copiar,
distribuir o usarlo en ningún sentido. Le rogamos lo comunique al remitente y
borre dicho mensaje y cualquier documento adjunto que pudiera contener. No hay
renuncia a la confidencialidad ni a ningún privilegio por causa de transmisión
errónea o mal funcionamiento.
Cualquier opinión expresada en este mensaje pertenece únicamente al autor
remitente, y no representa necesariamente la opinión de ISBAN, a no ser que
expresamente se diga y el remitente esté autorizado para hacerlo.
Los correos electrónicos no son seguros, no garantizan la confidencialidad ni
la correcta recepción de los mismos, dado que pueden ser interceptados,
manipulados, destruidos, llegar con demora o incompletos, o con virus. ISBAN no
se hace responsable de los cambios, alteraciones, errores u omisiones que
pudieran hacerse al mensaje una vez enviado.
Este mensaje sólo tiene una finalidad de información, y no debe interpretarse
como una oferta de venta o de compra de valores ni de instrumentos financieros
relacionados.
**********************DISCLAIMER*****************
This message is private and confidential and it is intended exclusively for the
addressee. If you receive this message by mistake, you should not disseminate,
distribute or copy this e-mail. Please inform the sender and delete the message
and attachments from your system. No confidentiality nor any privilege
regarding the information is waived or lost by any mistransmission or
malfunction.
Any views or opinions contained in this message are solely those of the author,
and do not necessarily represent those of ISBAN, unless otherwise specifically
stated and the sender is authorized to do so.
E-mail transmission cannot be guaranteed to be secure, confidential, or
error-free, as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. ISBAN does not accept
responsibility for any changes, errors or omissions in the contents of this
message after it has been sent.
This message is provided for informational purposes and should not be construed
as a solicitation or offer to buy or sell any securities or related financial
instruments.