You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Leonardo Uribe (Issue Comment Edited) (JIRA)" <de...@myfaces.apache.org> on 2011/11/08 22:03:52 UTC

[jira] [Issue Comment Edited] (MYFACES-3388) DataModelListener is not notified the very first time the UIData's row index changes from -1 to 0

    [ https://issues.apache.org/jira/browse/MYFACES-3388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13146565#comment-13146565 ] 

Leonardo Uribe edited comment on MYFACES-3388 at 11/8/11 9:03 PM:
------------------------------------------------------------------

I don't think add the code setValue() could be a good place to subscribe a DataModelListener. The spec is not clear about if is necessary to call setWrappedData() on the construction, but to honor the description on the spec it is necessary to call it, because in that place the conditions for publish DataModelEvent are checked. I think the only way to do what you expect is extends from UIData but reimplement that part of the algorithm (createDataModel), just like tomahawk does in its t:dataTable component. I'll close this issue as invalid, because the current behavior comply with the spec. Anyway, the hack proposed for your example sounds better than change myfaces core internals. 
                
      was (Author: lu4242):
    I don't think add the code setValue() could be a good place to subscribe a DataModelListener. The spec is not clear about if is necessary to call setWrappedData() on the construction, but to honor the description on the spec it is necessary to call it, because in that place the conditions for publish DataModelEvent are checked. I think the only way to do what you expect is extends from UIData but reimplement that part of the algorithm, just like tomahawk does in its t:dataTable component. I'll close this issue as invalid, because the current behavior comply with the spec. Anyway, the hack proposed for your example sounds better than change myfaces core internals. 
                  
> 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)
>            Assignee: Leonardo Uribe
>            Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> 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