TOC PREV NEXT INDEX



PDF
ICEfaces Online Reference




 


 




Modifying TimeZoneBean.java


Make the following additions to TimeZoneBean.java.

1. Add an import, to allow our use of JSF ValueChangeEvents.
import javax.faces.event.ValueChangeEvent;
 
2. Declare a list to hold the user's checked time zone selections.
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", "Cminus10"));
 
allTimeZoneList.add(new TimeZoneWrapper(
 
		"America/Anchorage", "GMTminus9", "Cminus9"));
 
allTimeZoneList.add(new TimeZoneWrapper(
 
		"America/Los_Angeles", "GMTminus8", "Cminus8"));
 
allTimeZoneList.add(new TimeZoneWrapper(
 
		"America/Phoenix", "GMTminus7", "Cminus7"));
 
allTimeZoneList.add(new TimeZoneWrapper(
 
		"America/Chicago", "GMTminus6", "Cminus6"));
 
allTimeZoneList.add(new TimeZoneWrapper(
 
		"America/New_York", "GMTminus5", "Cminus5"));
 

 
4. Initialize the list for storing the time zones that the user has checked, and wishes to display in the dataTable.
checkedTimeZoneList = new ArrayList();
 

 
5. Provide a getter accessor method for the checkedTimeZoneList bean property.
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.getCheckboxId(), 
 
									 checked ? "true" :"false");
 
			}
 
		}
 


Copyright 2005-2006. ICEsoft Technologies, Inc.
http://www.icesoft.com

TOC PREV NEXT INDEX