FileDocCategorySizeDatePackage
EntryHandler.javaAPI DocExample5488Tue Jun 08 11:26:42 BST 2004com.mycompany.expense

EntryHandler

public class EntryHandler extends Object
This class contains properties and methods for the JSF components in the report entry area of the sample expense report aplication.
author
Hans Bergsten, Gefion Software
version
1.0

Fields Summary
private ReportHandler
reportHandler
private ReportEntry
currentEntry
private Map
expenseTypes
private List
expenseTypeChoices
private Map
specialTypes
private List
specialChoices
private boolean
includeSpecial
Constructors Summary
Methods Summary
public java.lang.Stringadd()
Adds the current entry to the current report by calling the addEntry() method on the ReportHandler.

	return reportHandler.addEntry(currentEntry);
    
public java.util.ListgetCurrentChoices()
Returns a List with SelectItem instances for the expense type choices, including the special choices if the "includeSpecial" flag is set to "true".

	List choices = new ArrayList();
	choices.addAll(getExpenseTypeChoices());
	if (includeSpecial) {
	    choices.addAll(getSpecialChoices());
	}
	Iterator i = choices.iterator();
	while (i.hasNext()) {
	    SelectItem si = (SelectItem) i.next();
	}
	return choices;
    
public ReportEntrygetCurrentEntry()
Returns the current ReportEntry instance, or a new instance if there's no current instance.

	if (currentEntry == null) {
	    currentEntry = new ReportEntry();
	}
	return currentEntry;
    
public java.util.ListgetExpenseTypeChoices()
Returns a List with SelectItem instances for the standard expense type choices.

	if (expenseTypeChoices == null) {
	    expenseTypeChoices = new ArrayList();
	    Iterator i = expenseTypes.entrySet().iterator();
	    while (i.hasNext()) {
		Map.Entry me = (Map.Entry) i.next();
		expenseTypeChoices.add(new SelectItem(me.getValue(),
		    (String) me.getKey()));
	    }
	}
	return expenseTypeChoices;
    
public java.util.ListgetI18nChoices()
Returns a List with SelectItem instances matching the standard expense type choices with labels localized for the view's locale, from a resource bundle with the base name "entryTypes".

	FacesContext context = FacesContext.getCurrentInstance();
	Locale locale = context.getViewRoot().getLocale();
	ResourceBundle bundle = 
	    ResourceBundle.getBundle("entryTypes", locale);
	List i18nChoices = new ArrayList();
	Iterator i = expenseTypes.entrySet().iterator();
	while (i.hasNext()) {
	    Map.Entry me = (Map.Entry) i.next();
	    i18nChoices.add(new SelectItem(me.getValue(),
		getResource(bundle, (String) me.getKey())));
	}
	return i18nChoices;
    
private java.lang.StringgetResource(java.util.ResourceBundle bundle, java.lang.String key)
Returns the resource matching the provided key after replacing all spaces with underscores, or a String containing the key embedded in question marks if no resource matches the key.

	// Replace all spaces with underscore
	key = key.replaceAll(" ", "_");
	String resource = null;
	try {
	    resource = bundle.getString(key);
	}
	catch (MissingResourceException e) {
	    resource = "???" + key + "???";
	}
	return resource;
    
private java.util.ListgetSpecialChoices()
Returns a List with SelectItem instances for the special expense type choices.

	if (specialChoices == null) {
	    specialChoices = new ArrayList();
	    if (specialTypes != null) {
		Iterator i = specialTypes.entrySet().iterator();
		while (i.hasNext()) {
		    Map.Entry me = (Map.Entry) i.next();
		    specialChoices.add(new SelectItem(me.getValue(),
			(String) me.getKey()));
		}
	    }
	}
	Iterator i = specialChoices.iterator();
	while (i.hasNext()) {
	    SelectItem si = (SelectItem) i.next();
	}
	return specialChoices;
    
public voidsetExpenseTypes(java.util.Map expenseTypes)
Sets the standard expense type choice values.

	this.expenseTypes = expenseTypes;
    
public voidsetReportHandler(ReportHandler reportHandler)
Sets a reference to the ReportHandler that this instance interacts with.

	this.reportHandler = reportHandler;
    
public voidsetSpecialTypes(java.util.Map specialTypes)
Sets the special expense type choice values.

	this.specialTypes = specialTypes;
    
public voidtoggleTypes(javax.faces.event.ValueChangeEvent event)
Toggles the value of the "includeSpecial" flag. This method is used as value change listener method for an input component.

	includeSpecial = !includeSpecial;
	FacesContext.getCurrentInstance().renderResponse();
    
public java.lang.StringtoggleTypes()
Toggles the value of the "includeSpecial" flag. This method is used as an action method for a command component.

	includeSpecial = !includeSpecial;
	return "success";