As of the start of May I’ve got myself a new job, I’m now working for Isomorphic Software developing on the SmartClient framework which is a set of components for building rich web applications. Not to bore anyone with details about how extensive the framework you should just click the link and go have a look for your self.
Now onto the actual subject of this post, adding a sort order to a SelectItem used on a form. I wanted to ensure that a select box had it’s items sorted to make it easier for the user to find the item in the list, the items come from a second datasource as a simple select from query. On the SelectItem API you will find a method called setSortField(String) which allows you to tell it which field to sort the items in the select box by.
final SelectItem selectItem = (SelectItem) form.getField("teamId");
if (selectItem != null) {
selectItem.setSortField("name");
}
You can see in this small snippet that I’m checking to see if the selectItem is null, this is because the form I’m using here has dual purpose to edit different datasource and sometimes the SelectItem won’t be there but if you know you always have a SelectItem there should be no need for that check.

