combobox.java

来自「IBM RSA下的JSF开发示例」· Java 代码 · 共 116 行

JAVA
116
字号
/**
 * 
 */
package pagecode.eventHandling;

import pagecode.PageCodeBase;
import javax.faces.event.ValueChangeEvent;
import com.ibm.samples.eventHandling.CountriesValues;
import com.ibm.faces.component.html.HtmlScriptCollector;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlSelectOneMenu;
import com.ibm.faces.component.html.HtmlCommandExButton;

/**
 * @author nan
 *
 */
public class ComboBox extends PageCodeBase {

	protected CountriesValues continent;
	protected HtmlScriptCollector scriptCollector1;
	protected HtmlForm form1;
	protected HtmlSelectOneMenu continentMenu;
	protected HtmlSelectOneMenu countryMenu;
	protected HtmlCommandExButton button1;
	protected HtmlOutputText continentOutput;
	protected HtmlOutputText countryOutput;
	
	protected HtmlScriptCollector getScriptCollector1() {
		if (scriptCollector1 == null) {
			scriptCollector1 = (HtmlScriptCollector) findComponentInRoot("scriptCollector1");
		}
		return scriptCollector1;
	}
	
	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	}
	
	protected HtmlSelectOneMenu getContinentMenu() {
		if (continentMenu == null) {
			continentMenu = (HtmlSelectOneMenu) findComponentInRoot("continentMenu");
		}
		return continentMenu;
	}
	
	protected HtmlSelectOneMenu getCountryMenu() {
		if (countryMenu == null) {
			countryMenu = (HtmlSelectOneMenu) findComponentInRoot("countryMenu");
		}
		return countryMenu;
	}
	
	protected HtmlCommandExButton getButton1() {
		if (button1 == null) {
			button1 = (HtmlCommandExButton) findComponentInRoot("button1");
		}
		return button1;
	}
	
	protected HtmlOutputText getContinentOutput() {
		if (continentOutput == null) {
			continentOutput = (HtmlOutputText) findComponentInRoot("continentOutput");
		}
		return continentOutput;
	}
	
	protected HtmlOutputText getCountryOutput() {
		if (countryOutput == null) {
			countryOutput = (HtmlOutputText) findComponentInRoot("countryOutput");
		}
		return countryOutput;
	}
	

	/** 
	 * @managed-bean true
	 */
	public CountriesValues getContinent() {
		if (continent == null) {
			continent = (CountriesValues) getFacesContext().getApplication()
					.createValueBinding("#{continent}").getValue(getFacesContext());
		}
		return continent;
	}
	
	/** 
	 * @managed-bean true
	 */
	public void setContinent(CountriesValues continent) {
		this.continent = continent;
	}
	
	/*
	 * The Value Changed Event. It sets the current values selected by the user and populates the second
	 * combo box.
	 */
	public void handleMenu1ValueChange(ValueChangeEvent valueChangedEvent) {
		// Note, valueChangeEvent contains new and old values
		
		// get the new value
		String val = (String)valueChangedEvent.getNewValue();
		
		// set the new value in the bean
		getContinent().setCombo(val);
		
		// display second combo box
		getCountryMenu().setRendered(true);
		getFacesContext().renderResponse();
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?