Cannot Retrieve from Hashtable to Create a List
I receive a Hashtable from people working on the back end of the application. I am trying to convert the Hashtable with key/value pairs into an ArrayList, which is an array of a bean class with two properties: country code and country name.
I do not have compilation error nor runtime error. But, I simply do not get any data in my List. Please help to take a look at my code
In my constructor, I call a method from a Singleton class:
List countries =null;
public CountriesManagementBean()
{
countries = CountriesVO.getCountriesList();
}
And my Singleton class looks like:
// many import statements
import beans.CountryData;
publicclass CountriesVO
{
privatestatic VrDao daoVR =null;
privatestatic Hashtable countryTable =null;
privatestatic List<CountryData> countriesList =new ArrayList<CountryData>();
private CountriesVO(){}// prevent this class from being instantiated
publicstaticsynchronized List getCountriesList()
{
if ( countriesList ==null )
{
try
{
daoVR =new VrDao();
countryTable = daoVR.getCountryCds();// given by people working on the back end
Enumeration keys = countryTable.keys();
while ( keys.hasMoreElements() )
{
String countryCode = ( String )keys.nextElement();
String countryName = ( String )countryTable.get( countryCode );
CountryData data =new CountryData();
data.setCode( countryCode );
data.setDescription( countryName );
countriesList.add( data );
}// end while
}
catch (Exception ex){
ex.printStackTrace();
}
}
return countriesList;
}
}
The CountryData is the bean that I mentioned earlier. The CountryData.java has two propertied with their getters and setter:
publicclass CountryData
{
// Init -
private String code;
private String description;
// Getters -
public String getCode()
{
return code;
}
public String getDescription()
{
return description;
}
// Setters -
publicvoid setCode( String code )
{
this.code = code;
}
publicvoid setDescription( String description )
{
this.description = description;
}
}

