combobox - set default value; get selected value
843842Oct 4 2006 — edited Nov 5 2007Hi!
I have a combobox (h:selectOneMenu) in my application. I put the values in it from a java bean. I would like to set the default value of combo box, but I don't know how.
And I would like to know which value is selected, but I don't know as well.
Please help mt to find the solution of these 2 problems!
Thanks!
rfalir
******************************* JSP ***************************
<h:selectOneMenu id="type" binding="#{myComboBoxValuesBean.myBindingValuesForType}">
<f:selectItems value="#{myComboBoxValuesBean.valuesForType}"/>
</h:selectOneMenu>
***********************************bean***********************************
package bean;
import java.util.HashMap;
import java.util.Map;
import javax.faces.component.html.HtmlSelectOneMenu;
public class ComboBoxValuesBean {
HtmlSelectOneMenu myBindingValuesForType;
Map valuesForType;
// ************************** getter **************************
public HtmlSelectOneMenu getMyBindingValuesForType() {
return myBindingValuesForType;
}
public Map getValuesForType() {
if (valuesForType == null) {
initValuesForType();
}
return valuesForType;
}
// ************************** setter **************************
public void setMyBindingValuesForType(HtmlSelectOneMenu myBindingValuesForType) {
this.myBindingValuesForType = myBindingValuesForType;
}
public void setValuesForType(Map valuesForType) {
this.valuesForType = valuesForType;
}
// ************************** others **************************
private void initValuesForType() {
valuesForType = new HashMap();
valuesForType.put("Karakter","C");
valuesForType.put("Sz�m","N");
valuesForType.put("D�tum","D");
}
}