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 ComparatorDataRecord,
Serializable
{
private static final long serialVersionUID = 1L;
@SuppressWarnings({ rawtypes, unchecked })
public int compare(final DataRecord o1, final DataRecord o2)
{
PropertyModelComparable model1 = new
PropertyModelComparable(o1,
getSort().getProperty());
PropertyModelComparable model2 = new
PropertyModelComparable(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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org