Support for Interface java.util.Collection in HtmlDataTable with 
preserveDataModel not working
----------------------------------------------------------------------------------------------

         Key: MYFACES-273
         URL: http://issues.apache.org/jira/browse/MYFACES-273
     Project: MyFaces
        Type: Bug
    Versions: 1.0.9 beta    
 Environment: Tomcat 5.5.9 Windows XP
    Reporter: Rogerio Saulo
    Priority: Critical


Hi, 

I´m having problems with the user of x:dataTable and x:dataScroller when 
displaying hibernate generated collections (List).
In all my hibernate persistent objects I have the collection mapped as 
java.util.Collection, when I put in a page an x:dataTable referencing an 
Collection in the value attribute, AND THE PRESERVEDATAMODEL attribute is set 
to TRUE, I only got the first page, when attempt to go to the second page, I 
get an exception (Attempt to coerce a value of type 
"br.com.venus.model.valueobjects.UserVO" to type "java.util.Collection" ).
Well, I downloaded the last HEAD sources from CVS to investigate the error, and 
found that the error is in the 
org.apache.myfaces.component.html.ext.HtmlDataTable class, on the method 
updateModelFromPreservedDataModel(FacesContext context), the code from CVS is 
bellow :

    private void updateModelFromPreservedDataModel(FacesContext context)
    {
        ValueBinding vb = getValueBinding("value");
        if (vb != null && !vb.isReadOnly(context))
        {
            _SerializableDataModel dm = (_SerializableDataModel)_dataModel;
            Class type = vb.getType(context);
            if (DataModel.class.isAssignableFrom(type))
            {
                vb.setValue(context, dm);
            }
            else if (List.class.isAssignableFrom(type))
            {
                vb.setValue(context, (List)dm.getWrappedData());
            }
            else if (OBJECT_ARRAY_CLASS.isAssignableFrom(type))
            {
                List lst = (List)dm.getWrappedData();
                vb.setValue(context, lst.toArray(new Object[lst.size()]));
            }
            else if (ResultSet.class.isAssignableFrom(type))
            {
                throw new 
UnsupportedOperationException(this.getClass().getName() + " 
UnsupportedOperationException");
            }
            else
            {
                //Assume scalar data model
                List lst = (List)dm.getWrappedData();
                if (lst.size() > 0)
                {
                    vb.setValue(context, lst.get(0));
                }
                else
                {
                    vb.setValue(context, null);
                }
            }
        }
    }

In the code if the type variable is an Collection, not an List , the program 
will enter in the last else block and cast the object to List (This will work 
because Hibernate return an List object) and then try to set the binding to the 
first object of the list, is here that the error occurs.

I think that we need in that method another if asking if the Collection 
received is an instance of an Collection an not use the isAssignableFrom 
method, in that way, we will have problems with Interfaces, IMO that method 
need to work with any type of Collection.

Well, my question is, I´m thinking on the right way or exist another more 
elegant way to correct this problem??

Thanks
Rogerio


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to