1

This is my fragment, The fragment not have a controller

<core:FragmentDefinition
  xmlns="sap.m"
  xmlns:core="sap.ui.core">
  <Dialog
    title="Invio report via mail">
    <content>

        <FlexBox
            alignItems="Start"
            justifyContent="Center">
            <items>
             <TextArea id="idMailReport" value="themail.mail.it" rows="1" cols="50" /> 
            </items>
        </FlexBox>



    </content>
    <beginButton>
      <Button text="Ok" press="onDialogOkButton" />
    </beginButton>
    <endButton>
      <Button text="Close" press="onDialogCloseButton" />
    </endButton>
  </Dialog>


</core:FragmentDefinition>

Ho I can set che value of TextArea element?

I try to set it from a controller where I call the fragment:

var dialogFrafment = sap.ui.xmlfragment(
                "dialogFragment",
                "appIntra.fragment.dialog",
                this // associate controller with the fragment
          );
          this.getView().addDependent(dialogFrafment);
          dialogFrafment.open();
          this.byId("idMailReport").setValue("initial.mail.com");

Can you help me?

padibro
  • 1,324
  • 10
  • 56
  • 95
  • Does this answer your question? [How to Access Elements from XML Fragment by ID](https://stackoverflow.com/questions/39660161/how-to-access-elements-from-xml-fragment-by-id) – Boghyon Hoffmann Jul 12 '21 at 15:36

3 Answers3

6

please try

sap.ui.getCore().byId("idMailReport").setValue("initial.mail.com");

it should work.

Here is the official document.

wangf
  • 895
  • 9
  • 12
Haojie
  • 5,665
  • 1
  • 15
  • 14
  • Hi bradipo, please do the following:var dialogFrafment = sap.ui.xmlfragment( "appIntra.fragment.dialog", this // associate controller with the fragment ); – Haojie Jun 26 '14 at 08:29
  • :/ I see this article: http://goo.gl/rGKOoW Here http://pastebin.com/Y2eif0xU I declare my fragment. Here http://pastebin.com/5RVuchZv I create it and launch and test it The fregment opens without problems, but when I test `console.log(sap.ui.getCore().byId("idMailReport"));` it returns `undefined` – padibro Jun 26 '14 at 10:15
2

I solve it!

var dialogFrafment = sap.ui.xmlfragment(
                "appIntra.fragment.dialog",
                this.getView().getController() // associate controller with the fragment            
          );

my problem is that i had set a name of a fragment: "dialogFragment" Whitout it all work! ;)

padibro
  • 1,324
  • 10
  • 56
  • 95
  • `dialogFragment` was the *ID prefix* of the fragment, not the *name*. The reason why it worked: https://stackoverflow.com/a/47872515/5846045 – Boghyon Hoffmann Dec 18 '17 at 16:45
1

A bit outdated, but might be useful for others. When you reuse your fragment inside a view, giving it unique id like:

    var dialogFrafment = sap.ui.xmlfragment(
            "dialogFragment", // this is fragment's ID
            "appIntra.fragment.dialog",
            ...
      );

retrieving id of your nested control goes like:

this.byId(sap.ui.getCore().Fragment().createId("dialogFragment", "idMailReport"));

That way, your prepend fragment's id to your control's id.

empe3.X
  • 21
  • 4