Hi
I have searched through forum and didn’t find any info about that.
I want to have ComboBox with countries with flags to select (similar like in Sampler). Here are the codes:
public class CountriesComboBox extends ComboBox {
private static final List< CountryUI > countries;
static {
countries = Arrays.asList( CountryUI.values() );
}
public CountriesComboBox( String caption ) {
super( caption , countries );
this.setWidth( 12f , Sizeable.UNITS_EM );
this.setItemCaptionMode( AbstractSelect.ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID );
this.setNullSelectionAllowed( true );
this.setNullSelectionItemId( Integer.valueOf( 999 ) ); // <-- crucial line
for ( final CountryUI countryUI : countries ) {
CountriesComboBox.this.setItemIcon( countryUI , countryUI.getIcon() );
}
}
}
CountryUI is just an enum like this (cutted because of 246 countries in the list):
public enum CountryUI {
Afghanistan( Country.Afghanistan , "images/flags/af.png" ) ,
[...all countries in the format like above...]
private final Country country;
private final String iconPath;
private final Resource icon;
private CountryUI( Country country , String iconPath ) {
this.country = country;
this.iconPath = iconPath;
this.icon = new ThemeResource( iconPath );
}
[...getters...]
Problem with the example above (see attachment) is with numbering on the first “page”: 1-9/245. But number of countries is 246 (ISO-3166). Additionaly, when You count entries on the first page - there are 10 of them and not 9 like the info tells (1-9). On other pages - everything is correct: 10-19/245 etc. The crucial line here is:
this.setNullSelectionItemId( Integer.valueOf( 999 ) );
There are 3 cases:
- null selection item id is not null but doesn’t exist in combo entries (example above) and drop down list behaves as i explained above.
- null selection item id is set to null. Then, total number of countries shows correctly 246 but on the first page there are 9 of them (info is correct: 1-9/246) but on the other pages there are 10 shown (infos are also correct).
- null selection item id is not set (line commented). Then drop down list behaves corectly - 10 countries on every page, total number of countries is 246. But it is not what I want.
Generally saying, 2nd case works for me and 9 entries doesn’t bother me but I am just curious - why is it happen?
Is it a bug?