on 02-07-2014 11:07 AM
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
problem is in the view personalDetailEdit.view.js in row 143/144
Kind Regards,
Richard
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I tried your solution but nothing works.
Even when I use a hardcoded value like this it is not working.
source in onInit() in Controler of the view.
this.getView().addressTypeSelect.bindItems("/AddressSubtypeSet", this.getView().addressTypeSelectItems);
Source in the view
this.addressTypeSelect = new sap.m.Select("addressTypeSelectId",{selectedKey : "1"});
this.addressTypeSelectItems = new sap.ui.core.Item({
key : "{Subtype}",
text : "{SubtypeText}"
});
var addressTypeSimpleForm = new sap.ui.layout.form.SimpleForm({
minWidth : 1024,
maxContainerCols : 2,
editable : true,
content : [
new sap.ui.core.Title({text : "Adrestype"}),
new sap.m.Label({text : oBundle.getText("ADDRESSTYPE"),required : true}),
this.addressTypeSelect,
]
});
Actually, Not sure if it's a timing issue as it looks like the onBeforeRendering, should handle the scenario, however might be worth investigating.
// note: setSelectedKey() method sometimes is called
// before the items are added, in this case the "selectedItem" association
// and "selectedItemId" property need to be updated in onBeforeRendering()
Regards,
Jason
Hoi Jason,
Thanks for helping me!
I think that is the case! I'am new at developing in SAPUI5 so I have figure out how to use and change data in SAPUI5 application. In Webdynpro I know exactly where how it works.
How can I update the selectionKey in onBeforeRedering() based on my sample. I'm a little bit lost.
Kind Regards,
Richard
Hi Richard,
No worries, I think the onBeforeRendering method of the sap.m.Select control should automatically check the selectKey, so you shouldn't need to implement anything yourself.
I find it useful to look at the -dbg.js files for each of the controls to get a better understanding of how everything works, easier said than done when time is limited, but will be useful in the long run.
In terms of structuring the applications I think Bertram's Building Fiori like UIs, DJ's SublimeUI5 templates and Hans-Peter's SAPUI5 Boilerplate useful examples.
Personally I prefer to implement the Views in XML, I've think it removes some of the complexity you can inadvertently add to the views.
Going back to the select control it is possible to bind the selected item property to a model, so perhaps you can set on the model instead?
Regards,
Jason
Hi Jason,
I know flow of my application. The first time I trigger the detail screen from my selectionscreen it uses the following flow.
Vier -> onInit -> onBeforeShow -> beforeRendering ->AfterRendering. Next time it only calls the onBeforeShow.
In the onBeforeShow I get my binding from the selection screen with following source
onBeforeShow : function(oData) {
this.getView().bindElement(oData.bindingContext.getPath());
this.getView().nationality.setSelectedKey("NL");
},
Also I set my selectedKey here.
Now I facing a problem that when I call the screen for the first time my selected key is not set.
When I leave the screen and open the screen again the selectedKey is set.
How Can I trigger the setSelectionKey so that it is set correctly the first time and how get I the value of a field "Country" which is available in the oData.bindingContext.getPath().
Kind regards,
Richard
Hi Richard,
I'm not sure if you are over complicating this, I was able to bind to a simple example without the need to override any additional events??
Regards,
Jason
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.