Skip to Content
avatar image
Former Member

SelectedKey not set in sap.m.Select SAPUI5/odata

Hi all,

I have problem with add a oData value in SelectedKey of a sap.m.Select.

I try serveral ways to add the value to SelectedKey but nothing works.

I have publish the project to Github

eu.centric.entrada.persData/WebContent/app/persData at master · rmiddelburg/eu.centric.entrada.persData · GitHub

problem is in the view personalDetailEdit.view.js in row 143/144

Kind Regards,

Richard

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Sep 02, 2014 at 12:20 AM

    Hi Richard,

    Just ran into this problem, and figured a solution out and documenting here to make sure I understand it. Basically since the oData call is async, and the set key of the select happens prior; the first time you call this, it gets stuffed up, and if you've got 2-way binding, then it changes your value on you too to boot!

    So in order to get this right; I suggest getting the value you want to set; then using

    oModel.attachRequestCompleted("name of odata entityset", callbackfunctiontofixkey); in your onBeforeShow (or possibly onInit - I'm still playing around with it); then the callbackfunctiontofixkey can get the select control and set the selectedkey correctly (you may need to save this key in the case the select overwrites the key possibly).

    Actually - Scratch that - what you should do is not bind the selectedKey in your view until the call back function is called then set it by getting the select control and binding the property selectedKey:

    oSelect.bindProperty("selectedKey", "your odata entity property value");

    Hope that helps you and others as it's not obvious that binding with odata in selects can have race conditions that cause the key to default and overwrite values.

    Cheers,

    Matt

    Message was edited by: Matt Harding

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 08, 2014 at 07:10 AM

    Hi Middelburg,

    Check this.. this.nationality.setSelectedKey('/Nationality'),

    You are giving path but you are not binding the path value. I am thinking the above line you have check the syntax..

    Do one thing get the values in an array and give that array values as below if there are 'n' number of values..

    this.nationality.setSelectedKey(Nationality[0]), or if it is a single value give only 'Nationality'

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 11, 2014 at 01:55 PM

    Hi Jason,

    I simplefied my view by defining the select into the view!

    Like this:

          this.test = new sap.m.Select();

    //     this.test.setModel(oModel1);

          this.nationalitySelectItems = new sap.ui.core.Item({key: "{Land1}",text: "{Land1}"});

          this.test.bindItems("/CountryCodesSet", this.nationalitySelectItems);

          this.test.setSelectedKey("NL");

        

          sap.m.MessageBox.show("chosen key" +this.test.getSelectedKey());

         this.test;

    I see a list with countries and the first line is selected and has the value "TF". But Message shows that the selectedKey is "NL".

    Richard

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 18, 2016 at 02:43 PM

    Hi experts,

    I have this and works for me,

    <!--Binding label from Metadata. -->

    <Label text="{/#Bankdetails/Bnksa/@sap:label}" />

    <Select forceSelection="false"

    id="Bankdetails-Bnksa"   <-- is very important set id for select. In other case do not works.!!!

      selectedkey = "{/toBankdetails/Bnksa}"  <-- Binding from oModel in View

      items="{   path : '/Sh_BankdetailsClassSet',   <-- Binding to get from service GW that contains list of values

    filters: [

                  {

      path:'Infty',

      operator :'EQ',

      value1 : '0009'

        }

    ]

    }"

       >

      <core:Item key="{Subty}" text="{Stext}" />

      </Select>

    Add comment
    10|10000 characters needed characters exceeded