Wednesday Nov 07, 2007
Wednesday Nov 07, 2007
One may find it little difficult to load a properties file values into the dropdown list component of Sun Studio Creator 2 update 1. Here I have outlined the steps I have used to create it.
1. Check if the Component Library Manager contains the Property Resource Provider Library. This library provides components in Creator for reading Properties file. This library is very useful for localization. Here is an article on how it can be done. If you do not have the library in Creator, you can download it from here and import it into your Creator.

2. Make sure that dropdown list have been added to the web application page. The dropdown component will be known by its default name dropDown1 in the application code.
3. Make sure that a properties file exist with all key value pairs required for the lookup.
4. Right click on DropDown List and select 'Bind to data'. Under 'Data Provider to Bind to Dropdown1', make sure to select 'PropertyResourceProvider1'. 'Under Tab 'Bind to Data Provider', make sure a single valid key and single value field are selected from the left panes and right panes. Under 'Bind to Object' make sure PropertyResourceProvider1 is selected. Click Close.
5. Right Click on DropDown List and select 'Property Bindings', select 'PropertyResourceProvider1' as the Binding Target. Click Close.
6. Add the following code to dropdown list Page1 java source. The code will only work if the source and target setting for the project are changed from Java 1.4 to Java 1.5. This is due to the use of Generics ( found in Java 1.5). One will have to manually edit the project.properties under nbproject directory of this project and change java.source and java.target to a value of 1.5. Rebuilding project with clean option will remove this file. Reediting will be required. One will also have to add option '-source 1.5' to Project properties > Compiling > Additional compiler options. You will not be able to see 'Design Page' after making this change. Your project should however work from this point onwards when deployed.
Use the prerender method for loading the properties values
public void prerender() {
FieldKey [] fldkys = getPropertyResourceProvider1().getFieldKeys();
ArrayList<Option> options = new ArrayList();
for (int i = 0; i<fldkys.length; i++) {
String str1 = getPropertyResourceProvider1().getValue(fldkys[i]).toString();
System.out.println(" Field Key String "+str1);
options.add(new Option(fldkys[i].getDisplayName(), str1));
}
if(options.size() > 0){
Option[] optionsArray = new Option[options.size()];
optionsArray = options.toArray(optionsArray);
dropDown1.setItems(optionsArray);
}
}