Skip to Content
0

UI5 Binding to Dialog

Mar 22, 2017 at 09:05 AM

133

avatar image

How does one bind to a Dialog that has not yet been opened?.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Jun Wu Mar 22, 2017 at 06:19 PM
0
 this.oDialog.bindElement(oTableData[index]);  the parameter should be the path to the data, not the data directly.
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Much appreciated Jun Wu.

0
Akhilesh Upadhyay Mar 22, 2017 at 09:26 AM
0

1. Create a fragment file for dialog

2. add fragment to your view

<l:VerticalLayout>
    <l:content></l:content>
    <l:dependents>
        <core:Fragment fragmentName="demo.dialogFragment" type="XML"></core:Fragment>
    </l:dependents>
</l:VerticalLayout>

3. bind dialog

in onInit function of view, get dialog id which is defined in fragment ( this.oDialog = this.byId("dialogId") ),

//bind dialog in oninit or patterenroutmatch function
this.oDialog.bindElement(bindingPath);

4. open dialog

this.oDialog.open();

hope this help.

Show 10 Share
10 |10000 characters needed characters left characters exceeded

Ah, so you can get the Dialog ID even though have not opened the Dialog yet. That was my initial issue. Will try this now. Thanks. I'll post the results shortly.

0

yes please check, you can get the dialog by this.getView().byId() or this.byId().

0

Okay, I don't create a dialog like you do as I already have a controller and view, with a table displayed. The table has a button to say Insert new record or edit record (as not all the data can be displayed in the table) and whereupon the dialog is opened and either the new record or existing record can be edited via the Dialog.

I have code like so:

  
  if(!this.oDialog) {
    this.oDialog = sap.ui.xmlfragment("view.MyDialog", this );
    this.getView().addDependent(this.oDialog);
   }
  var newRecord = {};
  //Get existing 
  var oTableData = this.getView().byId("idTblMyTable").getModel("MyModel").getData();
  oTableData.push(newRecord);
  this.getView().byId("idTblMyTable").getModel("MyModel").setData(oTableData);
  //Just in case, refresh.
  this.getView().byId("idTblMyTable").getModel("MyModel").refresh();
  //Get index of new row, hopefully
  var index = oTableData.length -1;
  //Get Dialog ID
  this.oDialog = this.byId("idDialog");
  this.oDialog.bindElement(oTableData[index]);
  //Now Open Dialog
  this.oDialog.open();

If I comment out all code except the IF statement and the last statement to open the Dialog everything works, in that my Dialog opens and displays, except of course there is no bound data.

My onInit function sets up some data and binds this to my View table, and this seems to work.

What is not working is the statement this.oDialog = this.byId("idDialog");

My Dialog XML starts off with <Dialog id="idDialog ....

But, I also have a <SimpleForm id = "idSfrDialog> as well, and if I use this.oDialog = this.byId("idSfrDialog"); that also does not work either. So, it seems to the setting of this.oDialog that is failing, and that's perhaps why the bindElement is failing.

I have also tried missing out the setting this.oDialg as well as it's defined above in the IF statement, but of course it's not using .byId to retrieve the ID, so does not work.

Can anyone identify why I can't get the id from my Dialog view.

0

first of all, if you are adding fragment dynamically I am not sure you can get dialog as this.oDialog = this.byId("idDialog");, because if you are defining fragment into xml then only it will be rendered and above line of code will work.

and, if you have already dialog in oninit / IF statement, why you are trying to get it again, (as Jun also said).

just bind it.

0

I have found a rather good example (

https://openui5.hana.ondemand.com/#docs/guide/4da72985139b4b83b5f1c1e0c0d2ed5a.html )

The Dialog XML has a line like this:

<Dialogid="helloDialog" title="Hello {/recipient/name}"></Dialog>

My question is, how is /recipient/name being bound to this Dialog.

Why do all the examples I read miss this bit out. Either it's just so simple it does not need to be mentioned, which I suspect, or they just miss this out.

Anyone care to comment?

0

they didn't miss anything, you just don't understand binding fully.....

0

I like to think that I have reasonable understanding of binding nowadays Jun.

However, in the example I mentioned, NOWHERE is 'recipient' used as a binding value in the js code, and hence my comment. It is ONLY mentioned in the XML.

This was my point, there are countless Dialog examples that skirt over the issue, and the linked article I mentioned is one of them, I believe. ;)

In the meanwhile, I'm testing my binding using a bindingpath.

0

don't know what u are talking......

0

It's okay Jun, I have found this issue. The link I had only shows some of the source code. I have found another link that shows all of the code, and can see from that how it is working.

0

thats what i told you in my very first comment, like,

get ready your fragment with bindding path and all ( like view xml binding )

add fragment in your view xml

in views controller get dialog by id and bindelemnt with binding path or by any model.

for your example, you can refer this link where data (/recipient/name) is getting binded from a model defined in component.js file

0
Jun Wu Mar 22, 2017 at 12:04 PM
0

you can define the binding in the fragment if the binding is static, just like your view, do you need to open the view then define the binding??

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Mar 22, 2017 at 01:17 PM
0
 this.oDialog = this.byId("idDialog");

you already store the dialog in the controller(this), why bother to get it again?
Show 1 Share
10 |10000 characters needed characters left characters exceeded

What I can't find ANYWHERE, is a single example of a binding to a Dialog (XML).

I can use

sap.ui.getCore().byId('inputId').setValue("Smith");

and also getValue as well to retrieve the values entered, but what I can't seem to do is bind a single record (in my case) model to the Dialog. Then reference that model/field from within the Dialog (XML) within <Input/> as an example.

0