There has been a small bug for a while now in combo boxes where if the value of the combo box matched multiple entries in the list, then the bottom most entry would appear highlighted. The function that creates the html representation of the combo box had grown over time and had a lot of warts as new functionality was added. Here's some of the things you can do with a List p-tag:
- Set the choices dynamically from an action
- Set the choices from a keyword
- Set the choices from a choices="a,b,c" tag attribute
- Set the choices via a datasource="SELECT distinct Surname FROM PERSON" attribute to get the data direct from the database
- Support a missingvaluetext="Not in list" attribute so that when there is no entry in the list that matches one of the choices, the text "Not in list" is displayed
- Display a "read only" version when ?ReadPage is used in a URL
The great thing about p-tags is that just by changing the tag type (eg change "<P@List" to "<P@Checkbox") and the html representation is changed with no underlying code changes. Even better, action code can change the tag type on the fly, so if for example you want a field to vanish or become read only, change its type to "void" or "computed".
This is one of those portions of code where optimisation is important. I remember the first time I wrote it (in about august 2001), being a Java newbie I just used Strings and concatenated them together, a la: String s = "text" + s2 + "moretext" + s3; The funny thing with combos and list boxes, is that there can be thousands of entries (for example, imagine a list of employee names in a large company). That little String concatenation has a nasty effect on memory: Strings are immutable, each time you concatenate one with another, a third new object is created which causes a heavy hit on the garbage collector (and memory allocation). Soon after, I moved all the code to use a StringBuffer - the performance increase was huge.
In the newest change, there used to be a loop where the html "select" and "option" tags were made. This has now been replaced with a new HTMLDocumentItemChoice object which takes care of its own rendering. The logic and loop is now much smaller and uses less memory with performance on par (or a little better, 20,000 choices takes approximately 380ms to render on my laptop) with the old code.