In the case of the plotCity example, when you use the publish/subscribe system to update the widget's data, you are still using StateBean to get the data, which is stored in the cities.properties file.
Here are the contents of the cities.properties file:
AK=Anchorage,Fairbanks,Juneau,Nome AZ=Mesa,Phoenix,Scottsdale,Tucson CA=Los Angeles,Sacramento,San Diego,San Francisco OR=Bend,Eugene,Portland,Salem WA=Olympia,Seattle,Spokane,Tacoma
The event handler, as described in the next section, uses Ajax to send the selected state value to the StateBean object's getNewCities method, by way of a servlet. The getNewCities method gets the list of cities for the selected state from the properties file and loads the cities into a JSON array, as shown in the following code:
... cityNames = ResourceBundle.getBundle("plotCity.cities"); ... public String getNewCities(String state) throws JSONException{ JSONObject city = new JSONObject(); JSONArray cities = new JSONArray(); String[] names = null; try { names = cityNames.getString(state).split(","); } catch(Exception e){ return null; } for(int i = 0; i < names.length; i++){ city.put("label", names[i]); city.put("value", names[i]); cities.put(city); city = new JSONObject(); } jmaki.util.JSONUtil.jsonArrayToString(cities, new StringBuffer()); }
Loading Data Into a Widget in the plotCity Applicationgives step-by-step instructions for implementing plotCity to populate its widgets with data.