Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

combobox - set default value; get selected value

843842Oct 4 2006 — edited Nov 5 2007
Hi!
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");
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2007
Added on Oct 4 2006
10 comments
239 views