You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Shelli Orton <Sh...@sjrb.ca> on 2010/09/22 22:42:20 UTC

PropertyModel getObject returns null

Hi,

I followed the example on this page
https://cwiki.apache.org/WICKET/simple-sortable-datatable-example.html
to create a SortableDataProvider.  I am running into a
NullPointerException when my Comparator class' compare method is invoked
at 

int result = model1.getObject().compareTo(model2.getObject());

My class is exactly the same as the example code except for the type of
objects passed in to the method and used in <Type>.

The model1.getObject() is returning null.  I have confirmed in debugging
that model1 has both a valid expression and target set.

How does the object get set in a PropertyModel?

Thanks in advance!

Shelli

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


RE: PropertyModel getObject returns null

Posted by Shelli Orton <Sh...@sjrb.ca>.
I figured out what was happening.  The object returned by getObject is
the property value, not the model object (I'm still wrapping my head
around Wicket terminology/architecture).  I found this example of a
compare method that deals with nulls:

class DataRecordComparator implements Comparator<DataRecord>,
            Serializable
    {
        private static final long serialVersionUID = 1L;

        @SuppressWarnings({ "rawtypes", "unchecked" })
        public int compare(final DataRecord o1, final DataRecord o2)
        {
            PropertyModel<Comparable> model1 = new
PropertyModel<Comparable>(o1,
                    getSort().getProperty());
            PropertyModel<Comparable> model2 = new
PropertyModel<Comparable>(o2,
                    getSort().getProperty());

            int result = 0;

            if (model1.getObject() == null && model2.getObject() ==
null)
            {
                result = 0;
            }
            else if (model1.getObject() == null)
            {
                result = 1;
            }
            else if (model2.getObject() == null)
            {
                result = -1;
            }
            else
            {
                result = ((Comparable)
model1.getObject()).compareTo(model2.getObject());
            }
            if (!getSort().isAscending())
            {
                result = -result;
            }

            return result;
        }
    }


-----Original Message-----
From: Shelli Orton 
Sent: Wednesday, September 22, 2010 2:42 PM
To: users@wicket.apache.org
Subject: PropertyModel getObject returns null

Hi,

I followed the example on this page
https://cwiki.apache.org/WICKET/simple-sortable-datatable-example.html
to create a SortableDataProvider.  I am running into a
NullPointerException when my Comparator class' compare method is invoked
at 

int result = model1.getObject().compareTo(model2.getObject());

My class is exactly the same as the example code except for the type of
objects passed in to the method and used in <Type>.

The model1.getObject() is returning null.  I have confirmed in debugging
that model1 has both a valid expression and target set.

How does the object get set in a PropertyModel?

Thanks in advance!

Shelli

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org