|
Modifying TimeZoneBean.java
Make the following additions to TimeZoneBean.java.
import javax.faces.event.ValueChangeEvent; import javax.faces.component.UIComponent; import java.util.Hashtable;private ArrayList checkedTimeZoneList;3. Give the IDs of the selectBooleanCheckbox components, from timezone.jspx, for their respective time zones. These are Cminus5 through Cminus10. This way, when we receive a ValueChangeEvent, we'll know to which time zone it applies.
allTimeZoneList.add(new TimeZoneWrapper("Pacific/Honolulu", "GMTminus10", hawaiiXCoords, hawaiiYCoords, hawaiiXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Anchorage", "GMTminus9", alaskaXCoords, alaskaYCoords, alaskaXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Los_Angeles", "GMTminus8", pacificXCoords, pacificYCoords, pacificXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Denver", "GMTminus7", mountainXCoords, mountainYCoords, mountainXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/Chicago", "GMTminus6", centralXCoords, centralYCoords, centralXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("America/New_York", "GMTminus5", easternXCoords, easternYCoords, easternXCoords.length)); allTimeZoneList.add(new TimeZoneWrapper("Canada/Newfoundland", "GMTminus4", nfldXCoords, nfldYCoords, nfldXCoords.length));4. Initialize the list for storing the time zones that the user has checked, and wishes to display in the dataTable.
checkedTimeZoneList = new ArrayList();public ArrayList getCheckedTimeZoneList(){ return checkedTimeZoneList; }6. Add a timeZoneChanged(ValueChangeEvent event) method to be called when a selectBooleanCheckbox is checked or unchecked. This uses our TimeZoneWrapper helper objects to map from the selectBooleanCheckbox component ID to the appropriate time zone, and its related information. Simply adding or removing the TimeZoneWrapper to or from checkedTimeZoneList is sufficient to add or remove a row in the web page's dataTable.
public void timeZoneChanged(ValueChangeEvent event){ UIComponent comp = event.getComponent(); FacesContext context = FacesContext.getCurrentInstance(); String componentId = comp.getClientId(context); TimeZoneWrapper tzw = getTimeZoneWrapperByComponentId( componentId ); if( tzw != null ) { boolean checked = ((Boolean)event.getNewValue()).booleanValue(); // If checkbox is checked, then add tzw to checkedTimeZoneList if( checked ) { if( !checkedTimeZoneList.contains(tzw) ){ checkedTimeZoneList.add( tzw ); } // Otherwise, if checkbox is unchecked, then remove tzw from // checkedTimeZoneList else { checkedTimeZoneList.remove( tzw ); } } checkboxStates.put(tzw.getMapCommandButtonId(), checked ? "true" : "false"); } }
Copyright 2005-2009. ICEsoft Technologies, Inc. |