Combobox - set default value; get selected value

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");
}

h:selectOneMenu works as following:
JSF<h:selectOneMenu value="#{myBean.selectedItem}">
    <f:selectItems value="#{myBean.selectItems}" />
</h:selectOneMenu>MyBeanprivate String selectedItem;
public String getSelectedItem() {
    if (selectedItem == null) {
        selectedItem = "key2"; // default value;
    return selectedItem;
public void setSelectedItem(String selectedItem) {
    this.selectedItem = selectedItem;
public List getSelectItems() {
    List selectItems = new ArrayList();
    selectItems.add(new SelectItem("key1", "value1");
    selectItems.add(new SelectItem("key2", "value2");
    selectItems.add(new SelectItem("key3", "value3");
    return selectItems;
}

Similar Messages

  • How to get selected value from selectOneRadio ???

    Hi...i want to how to get selected value from selectOneRadio and use it in another page and in backing bean.
    Note i have about 10 selectOneRadio group in one page i want to know value of each one of them.
    Plzzzzzzzz i need help

    You have a datatable in which each row is a question, correct?
    Also in each row you have 5 possible answers that are in a radio, correct?
    So,
    You need to put in your datatable model, a question, and a list of answers (5 in yor case) and the selected one.
    So you will have a get to the question, an SelectItem[] list to populate the radios and another get/set to the selected question.
    ex:
    <h:selectOneRadio value="#{notas.selectedString}" id="rb">
    <f:selectItem itemValue="#{notas.valuesList}"/>
    </h:selectOneRadio>
    Search the web for examples like yours.

  • Getting selected values from a data table

    My data table gets values directly from a result set.
    I went through http://balusc.blogspot.com/2006/06/using-datatables.html#top ,
    however, the data table shown in this example takes values from a simple list. I have trouble in getting selected values.
    Can anyone suggest how to select multiple values. here is a small code sample of what I have
    SessionBean
    ResultSet rs= db.retrieve_draft();
    datamodel = new ResultSetDataModel();
    datamodel.setWrappedData(rs);This is the JSF
    <h:dataTable binding="#{Engineer.dataTable1}" headerClass="list-header" id="dataTable1"
    rowClasses="list-row-even,list-row-odd" style="left: 144px; top: 192px; position: absolute"
    value="#{SessionBean1.datamodel}" var="currentRow">
    <h:column id="column1">
    <h:outputText id="outputText77" value="#{currentRow['report_number']}"/>
    <f:facet name="header">
    <h:outputText id="outputText78" value="Report Number"/>
    </f:facet>
    </h:column>Edited by: ktip on Jul 29, 2008 11:04 AM

    Here is what I was doing :
    This is my Session Bean (viz. SessionBean1)
    private CachedRowSetDataProvider draft_infoDataProvider;
        private CachedRowSetXImpl draft_RowSet;
        public CachedRowSetDataProvider getDraft_info() {
            return draft_infoDataProvider;
        public void setDraft_info(CachedRowSetDataProvider draft_info) {
            this.draft_info = draft_infoDataProvider;
        public CachedRowSetXImpl getDraft_RowSet() {
            return draft_RowSet;
        public void setDraft_row(CachedRowSetXImpl draft_row) {
            this.draft_row = draft_RowSet;
    public void get_drafts()
                Class.forName("com.mysql.jdbc.Driver");
                String url = "jdbc:mysql://localhost:3308/test";
                String dbUser = "root";
                String dbPassword = "adminadmin";
                con = DriverManager.getConnection(url, dbUser, dbPassword);
            String  sql="SELECT report_id from reports WHERE status='Draft' ";
            ResultSet rs=null;
            try
                Statement stmt1=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                rs=stmt1.executeQuery(sql);
                draft_RowSet=new CachedRowSetXImpl();
                draft_RowSet.populate(rs);
                draft_infoDataProvider=new CachedRowSetDataProvider(draft_RowSet);
                result="ok";
            catch(SQLException e)
              System.out.println(e); 
              result="fail";
    Here is my jsp page (developed in Netbeans 6.1) showing the data table
    <webuijsf:table augmentTitle="false" binding="#{Engineer.table1}" clearSortButton="true" deselectMultipleButton="true"
                                            id="table1" selectMultipleButton="true" sortPanelToggleButton="true"
                                            style="left: 48px; top: 144px; position: absolute; width: 450px" title="Table" width="0">
             <webuijsf:tableRowGroup id="tableRowGroup1" rows="10" sourceData="#{SessionBean1.draft_infoDataProvider}" sourceVar="currentRow">
                      <webuijsf:tableColumn headerText="report_number" id="tableColumn1" sort="test_report.report_number">
                                            <webuijsf:staticText id="staticText1" text="#{currentRow.value['reports.report_id]}"/>
                        </webuijsf:tableColumn>
             </webuijsf:tableRowGroup>
       </webuijsf:table>Doing all this just resulted in a javax.Naming.Exception : Data Source is null
    I tested this piece of code to give me the number of rows in the underlying rowset and it worked well. But somehow I could not get to display the data. Am I missing something?
    Edited by: ktip on Jul 31, 2008 1:21 PM

  • How to get selected value from OADefaultListBean.

    Hi All,
    How to get selected value from OADefaultListBean ?
    Thanks,

    Hi,
    To identify the user's selection(s) when the page is submitted, you would add the following logic to your processFormRequest() method:
    OADefaultListBean list =
    (OADefaultListBean)webBean.findChildRecursive("positionsList");
    String name = list.getName();
    String[] selectedValues = pageContext.getParameterValues(name);
    To retrieve all the values in the list box, call list.getOptionsData().
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to get selected value from one choice list

    Hi All,
    i want to get selected value in onechoice list.how to achive this
    Regards,
    Smaran

    check these
    http://groundside.com/blog/DuncanMills.php?title=adf_the_list_binding_value_problem&more=1&c=1&tb=1&pb=1
    http://blogs.oracle.com/jdevotnharvest/2010/12/reading_the_selected_value_of_an_adf_bound_select_list_in_java.html
    http://www.oracle.com/technetwork/developer-tools/jdev/listbindingvalue-088449.html

  • How to get selected value from SelectOneChoice

    Hi,
    I'm facing a problem to get selected value from SelectOneChoice. I have valueChangeListener event on a (SelectOneChoice)item. After user makes a choice I want to store selected value in a bean property to pass it to a method.
    For example List item shows dname from dept table after user makes a choice I want to get deptno and populate into bean which I use to pass into my method.
    If I use valueChangeEvent.getNewValue() I always get negative value instead I want deptno selected. Sample code pasted below.
    public void setDeptno(ValueChangeEvent valueChangeEvent) {
    BindingContainer b = getBindings();
    OperationBinding oB = b.getOperationBinding("setDeptno");
    //Checking instance of because same method is called from another text inputText item.
    if (valueChangeEvent.getSource() instanceof CoreSelectOneChoice){
    CoreSelectOneChoice cN = (CoreSelectOneChoice)valueChangeEvent.getSource();
    if (columnName.getId().toString().equals("deptDname")){
    JSFUtils.setManagedBeanValue("dept.deptDeptno",valueChangeEvent.getNewValue());
    }

    if your selectOneChoice has value equal to #{bindings.deptno} bound to the iterator Dept1Iterator,
    then the backing code will look more like
                    public void setDeptno(ValueChangeEvent valueChangeEvent) {
                        BindingContainer b = getBindings();
                        OperationBinding oB = b.getOperationBinding("setDeptno");
                        //Checking instance of because same method is called from another text inputText item.
                        if (valueChangeEvent.getSource() instanceof CoreSelectOneChoice){
                            CoreSelectOneChoice cN = (CoreSelectOneChoice)valueChangeEvent.getSource();
                        if (columnName.getId().toString().equals("deptDname")){
                            FacesContext ctx = FacesContext.getCurrentInstance();
                            Application app = ctx.getApplication();
                            ValueBinding bind = app.createValueBinding("#{bindings.Dept1Iterator.currentRow}");
                            Row row = (Row)bind.getValue(ctx);
                            JSFUtils.setManagedBeanValue("dept.deptDeptno", row.getAttribute("deptno"));
                    } I haven't tested it, so it could perfectly not work at all

  • Dvt:pivotFilterBar - how to get selected values from filter

    Hi all,
    I have a question: how to programmatically get selected values from pivot table's filter bar?
    I have tried to use
    pivotTable.getDataModel().getDataAccess().getValueQDR(startRow, startCol, DataAccess.QDR_WITH_PAGE);but for page edge dimensions it returns BAD DATA, it seems that it returns some cached values.
    Environment: JDev 11.1.1.3.0 without any patches.
    thanks,
    Miroslaw

    Hi,
    You can retrieve the selected value in the PivotFilterBar through the model of PivotFilterBar, instead of dataaccess:
    // get the model from the pivot filter bar instance
    QueryDescriptior queryDescriptor = (QueryDescriptor)pivotFilterBar.getValue();
    // retrieve a list of criterion, each one is used to populate each lov within the pivot filter bar
    ConjunctionCriterion conjunctionCriterion = queryDescriptor.getConjunctionCriterion();
    List<Criterion> criterionList = conjunctionCriterion.getCriterionList();
    for (int i=0; i<_criterionList.size(); i++) {
    AttributeCriterion criterion = (AttributeCriterion)criterionList.get(i);
    // _selected is the currently selected value
    Object selected = criterion.getValues().get(0);
    System.out.println(_selected);
    Hope that helps,
    Chadwick

  • Get selected values from Listbox control

    Hi All,
    I'm still new to SL so please bear with me.
    I have a ListBox being bound with some records from a DB.  Here's the xaml:
    <ListBox x:Name="lstClassSeries" SelectionMode="Multiple" DisplayMemberPath="Description" Grid.Row="11" Grid.Column="1"></ListBox>
    What I need is to get the values of the items that were selected and I can't seem to get it to work.  I've tried looping through the SelectedItems but there's no property for value or text.  I even tried to cast the item as a ListBoxItem but I
    get the following error:
    Unable to cast object of type 'UI.Silverlight.TransactionService.DTODropDown' to type 'System.Windows.Controls.ListBoxItem'.
    How can I get the values of the items selected?
    Thanks

    You're using windows forms style techniques with xaml.
    This is a bad idea.
    You ought to learn MVVM.
    You probably don't think you want to learn it, but trust me on this one.
    Learn MVVM as soon as you can.
    There's a selecteditems collection.
    You have to cast   to listboxitem, it has a content property which you cast to whatever you put in there originally.
    Here's a snippet.
    I have a class foo, load a bunch of them in.  Do stuff. Work out what's selected in the click event of a button.
    public class foo
    public int id {get;set;}
    public string description {get;set;}
    public partial class MainPage : UserControl
    public MainPage()
    InitializeComponent();
    lb.Items.Add(new ListBoxItem{Content=new foo{ id=1, description="a"}});
    lb.Items.Add(new ListBoxItem { Content = new foo { id = 2, description = "b" } });
    lb.Items.Add(new ListBoxItem { Content = new foo { id = 3, description = "c" } });
    private void Button_Click(object sender, RoutedEventArgs e)
    List<foo> selectedfoos = lb.SelectedItems.Cast<ListBoxItem>().Select(x=>x.Content as foo).ToList();
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • SelectManyShuttle: get selected values

    Hi all.
    My task is to make declarative component (or any other reusable solution) which contains select many shuttle component and should do some processing of selected values (both id and label). While doing this, I found that shuttle component returns to bean always & only item indexes, nothing more.
                  <af:selectManyShuttle label="" id="sms1"
                                        styleClass="AFStretchWidth"
                                        value="#{MyBean.selected}"
                                        valueChangeListener="#{MyBean.shuttleChangeListener}"
                                        valuePassThru="true">
                    <f:selectItems value="#{attrs.items}" id="si1"/>
                  </af:selectManyShuttle>First of all, I tried MyBean.setSelected and found it's called with List<Integer> instead of List<SelectItem> or any similar. These integers was selected rows' 0-based indexes. Then I tried to set valuePassThru, but it triggered a mocking effect only: setSelected receives List<String> with same 0-based index values stringified. At last, I tried valueChangeListener & newValues - all was the same, both in JDeveloper 11.1.1.5 & 11.1.2.1 with corresponding ADFs. Googling got me a lot of links - say, Need to get the selected values from the selectManyShuttle - but nothing I can use.
    Maybe I should get a model and iterate it, but in several tries (say, ((MyBean)this).getAttribute('items')) I failed to locate it. Anyway, I'd be glad to see any working solution.

    It cannot been casted itself, but FacesCtrlListBinding can. Thank you, Timo & Frank, all correct. I changed component's parameter from ListOfValueModel items to model itself, and after it code like
        FacesContext ctx = FacesContext.getCurrentInstance(); 
        ExpressionFactory ef = ctx.getApplication().getExpressionFactory(); 
        ValueExpression ve = ef.createValueExpression(ctx.getELContext(), "#{attrs.items}", Object.class); 
        Object list = ve.getValue(ctx.getELContext());    
        for (int i: getSelected() /* list.getSelectedIndices() is empty now */ ) {
          Row row = ((JUCtrlListBinding)list).getRowAtRangeIndex(i);
        ...works.

  • Getting selected values from selectManyChoice component inside valueChangeListener

    Hwo do I get the selected values from the selectManyChoice component inside the valueChangeListener.
    The API docs for valueChangeEvent.getNewValue() show the return type as java.lang.object. This is good for single value what does it return in case of multiple values.
    My drop down has string values so I am expecting a set of string values.

    JDev - 11.1.2.3
    public void onRegionSelect(ValueChangeEvent event) {
    event.getComponent().processUpdates(FacesContext.getCurrentInstance());
    if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
    event.setPhaseId(PhaseId.INVOKE_APPLICATION);
    event.queue();
    } else {
    List<Object> values = Arrays.asList(event.getNewValue());
    System.out.println("Value changed ==>> "+values.size());
    DCBindingContainer dc =
    (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding iter = dc.findIteratorBinding("RegVO1Iterator");
    ViewObject vo = iter.getViewObject();
    StringBuffer regions = new StringBuffer();
    for(Object index : values){
    String iIndex = (String)index;
    Row row  = vo.getRowAtRangeIndex(Integer.parseInt(iIndex));
    regions.append((String)row.getAttribute("Region")+",");
    String reg = regions.toString();
    if(reg.endsWith(","))
    reg = reg.substring(0,reg.lastIndexOf(","));
    System.out.println(reg);

  • How to get selected value from a listbox

    Hi !
    I use following code to fill in my LISTBOX with values :
    AT SELECTION-SCREEN OUTPUT.
      val-key = 1.
      val-text = '0016'.
      APPEND val TO list_values.
      val-key = 2.
      val-text = '0028'.
      APPEND val TO list_values.
      val-key = 3.
      val-text = '0035'.
      APPEND val TO list_values.
      val-key = 4.
      val-text = '2001'.
      APPEND val TO list_values.
      val-key = 5.
      val-text = '0515'.
      APPEND val TO list_values.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING id     = 'p_list'
                  values = list_values.
    My question is - how to get a selected key/text value ? i dont need it to be done dynamically - i just need it in START OF SELECTION to perform tasks.
    Thx in advance.

    Unfortunetly it does not work
    i Define parameter as follows :
    PARAMETERS:
      p_list AS LISTBOX VISIBLE LENGTH 10.
    Then i add values to it :
    AT SELECTION-SCREEN OUTPUT.
      val-key = 1.
      val-text = '0016'.
      APPEND val TO list_values.
      val-key = 2.
      val-text = '0028'.
      APPEND val TO list_values.
      val-key = 3.
      val-text = '0035'.
      APPEND val TO list_values.
      val-key = 4.
      val-text = '2001'.
      APPEND val TO list_values.
      val-key = 5.
      val-text = '0515'.
      APPEND val TO list_values.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING id     = 'p_list'
                  values = list_values.
    Then when i add a blank section :
    AT SELECTION-SCREEN ON p_list.
    I set a breakpoint in START OF SELECTION block - but the value is empty no matter what do i select.
    Actually when i select value from the list and hit enter key on selection screen the selection in a listbox goes empty :/
    Whats the cause of this ?
    Edited by: Jacek Zebrowski on Feb 26, 2009 12:38 PM

  • ADF  Get selected values from Dynamic Lists

    Hi,
    I have a created a dropdown list box where the list gets value through a managed bean. On commit I want the selected value to be saved into the CardiacV1EchoSched column of the Entity object (database). The source looks like this.
    <af:selectOneChoice value="#{bindings.CardiacV1EchoSched.inputValue}"
    label="#{bindings.CardiacV1EchoSched.label}"
    valuePassThru="true">
    <f:selectItems value="#{TTrack.carScheList}"/>
    </af:selectOneChoice>
    The problem is that getCardiacV1EchoSched() in the entity object class is null. The selected value does not get passed into #{bindings.CardiacV1EchoSched.inputValue} at all. If I bind the value to a variable in managed bean I get the selected value.
    Thanks in advance,

    Hi,
    not sure which business service you use to update the database, but if you use ADF Business Components then you need to call the commit operation
    Frank

  • How to get selected values from selectManyCheckbox ?

    Hi,
    I am a SOA developer and using 'Auto generated adf form' of Human Task. I did some customization in the form. I need to show one dynamic list (contains multiple string values) on a form, from which user will select desired values. For this I have used <af:selectManyCheckbox> adf component.
    It has generated code as follows...
    <af:selectManyCheckbox value="#{bindings.Response.inputValue}"
                                             label="#{bindings.Response.label}"
                                             id="smc1">
                        <f:selectItems value="#{bindings.Response.items}" id="si9"/>
    </af:selectManyCheckbox>
    I am able to show list on a form and can select multiple values also.
    Now, I want the multiple selected values back in my BPEL process. I need only those values which are selected by user.
    Currently I am getting complete list as it is back in BPEL process.
    Please help me out..!
    Thanks..
    Suraj

    Unwinding ADF: How to retrieve Selected Items from selectManyCheckbox using ValueChnageListener

  • How to get selected values from af:selectManyCheckbox

    Hi i am using jdeveloper 11.1.2 and i drag n drop a view object as Multiple select (<af:selectManyCheckbox) component and now i am trying to get the checked values in backing bean so that i can save in the database.
    Right now i am getting all the values but not the selected values.
    JSPX Page.
    <af:selectManyCheckbox value="#{bindings.HREmpDetailsVO1.inputValue}"
    label="EMPLOYEES"
    binding="#{backingBeanScope.backing_TestForm.smc1}"
    id="smc1">
    <f:selectItems value="#{bindings.HREmpDetailsVO1.items}"
    binding="#{backingBeanScope.backing_TestForm.si1}"
    id="si1"/>
    </af:selectManyCheckbox>
    Bean Class:
    public List getSelectedValues() {
    if (selectedValues == null || refreshSelectedList) {
    selectedValues =
    attributeListForIterator(selectedValuesIteratorName,
    selectedValuesValueAttrName);
    return selectedValues;
    public static List attributeListForIterator(DCIteratorBinding iter,
    String valueAttrName) {
    List attributeList = new ArrayList();
    for (Row r : iter.getAllRowsInRange()) {
    attributeList.add(r.getAttribute(valueAttrName));
    return attributeList;
    Can some one pls help me in getting the values with sample code.
    Thanks in advance

    Thank you so much for your help. But i am getting null values in the SOP. I could get count of selected values but not the values.

  • How to get selected values from Select Many Choice List

    Hello All -
    I am using Select Many Choice List and wish to get the selected values in the bean. I have created method binding for valueChangeListener for the choice list, but not sure how to get the selected values.
    I am facing problem in getting values from valueChangeEvent.getNewValue(). For Select One Choice List this returns int, but some list type object for Select Many Choice List.
    When I try to print the value it comes something like:
    ArrayList newVal = new ArrayList(Arrays.asList(valueChangeEvent.getNewValue()));
    System.out.println(newVal);
    [Ljava.lang.Integer;@870ad8
    Could anyone please suggest how to type cast and use the return of valueChangeEvent.getNewValue() to get the selected values.
    Regards -
    Rohit

    Hi Timo -
    Thanks for the suggestion. I could get the values as below:
    public void multiOpUnitValChange(ValueChangeEvent valueChangeEvent) {
    // Add event code here...
    BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding opUnitIter = (DCIteratorBinding)bindings.get("OperatingUnit2VOIterator");
    Integer[] values = (Integer[])valueChangeEvent.getNewValue();
    for (int i=0; i<values.length; i++){
    Row row = opUnitIter.getRowAtRangeIndex(i);
    System.out.println(row.getAttribute("OpUnitId"));
    Thanks -
    Rohit

Maybe you are looking for