MyBeanComparator.javaGeneric reflection-based bean comparator with natural and alphanumeric sort support. 139 lines. Sorts any list of Java beans by one or two properties using runtime reflection — no compile-time type safety on the property name. This is the comparator used by Wicket's SortableDataProvider in every list page — when a user clicks a column header to sort, this comparator is instantiated with the column's property name and sort direction.
BeanHelper.getNestedProperty(obj, "address.city") — dot notation traverses object graphs: user.getAddress().getCity()@StringAlphanumericSort, uses se.sawano.java.text.AlphanumericComparator which correctly sorts "file2.txt" before "file10.txt" (natural sort order)String.valueOf() comparison — this handles mixed-type lists gracefullyThe checkAnnotation() method checks if the property's getter/field has the @StringAlphanumericSort annotation. This annotation on a DO field means "sort this column alphanumerically, not lexicographically." Example: a field displaying document names like "Report1", "Report2", "Report10" — lexicographic sort gives "Report1", "Report10", "Report2"; alphanumeric gives "Report1", "Report2", "Report10". Both objects must have the annotation for alphanumeric sort to be used — otherwise falls back to standard String.compareTo().
If property access throws any exception (e.g. NoSuchMethodException for a misspelled property name), the error is logged and 0 is returned — the two objects are considered equal for sorting purposes. This prevents a single bad property name from breaking an entire list page. This is a fail-safe design — the user sees unsorted data rather than an error page.