cancel
Showing results for 
Search instead for 
Did you mean: 

Create link in message Box - SAP Ui5

Former Member
0 Kudos

Lets say upon GRN posting , i received one message with link and when i click on link i get navigated to GRN page.

I want to know how to bring link on message box.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thank You All for giving reply but my requirement is different , i am working with XML.

Please find below the code.

Layout.fragment.xml

--------------------------------------------

<core:FragmentDefinition

  xmlns="sap.m"

  xmlns:l="sap.ui.layout"

  xmlns:core="sap.ui.core">

<l:VerticalLayout> 

     <Link

        text="{/message}"

        press="handleLinkPress" />

</l:VerticalLayout>

</core:FragmentDefinition>

Master Controller.js

var mess = res.error.message.value;

  var oData = {

       message : mess

     };

     var oModel = new sap.ui.model.json.JSONModel(oData);

     var oView = selfView.getView();

     oView.setModel(oModel);

   

     if (!this._oLayout ) {

       this._oLayout  = sap.ui.xmlfragment("cgi_GoodsReceipt_GRN.view.Layout", this);

  selfView.getView().addDependent(this._oLayout);      }

 

     sap.m.MessageBox.show(this._oLayout  , {

      icon : sap.m.MessageBox.Icon.WARNING,

           title : "Successful Message",

           actions : [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],

           onClose : function(oAction) {

          

           },

           dialogId : "messageBoxId"

         });

----------------------------------------------------------------------------------------- event handler in Master Controller.js

handleLinkPress : function(oEvent)

  {

  var unit = selfView.byId('Master--idUnitType1')

  .getValue();

  console.log(unit);

  debugger;

  },

Now this handler is not getting triggered. And this is the issue which i am facing. I am getting link displayed in message box. when i click on link the handler is exepected to get triggered but it is not getting trigerred.

Former Member
0 Kudos

Correct Answer

var link = new sap.m.Link({

         text: mess,              

         press:  [selfView.handleLinkPress, this]       

   });

  

  sap.m.MessageBox.show(link, {

      icon : sap.m.MessageBox.Icon.WARNING,

           title : "Successful Message",

           actions : [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],

            onClose : function(oAction) {

            debugger;

           },

           dialogId : "messageBoxId"

         });

Answers (3)

Answers (3)

0 Kudos

Hi!

var oButtonClose = new sap.m.Button({ text: "Close",
                                           type: "Reject" } );
                     oButtonClose.attachBrowserEvent('click',function(){ oDialogInfo.close(); });
                 var oDialogInfo =
                   new sap.m.Dialog({ title: "Your title",
                              contentWidth: "400px",
                              contentHeight: "320px",
                              content: [
                 (new sap.m.Link({ text: "google.com - this link text",
                                            href: "google.com",

                                            target: "_self" })) //if new window "_blank"
                                          ],
                                    buttons: [ oButtonClose ]
                   });
                 oDialogInfo.open();


santhu_gowdaz
Active Contributor
0 Kudos

Same code is working fine for me, just i added "https://" infront of "google.com"

In my view.xml,

<Button id="" text="open" press="open" />

In my Controller.js,

    open:  function() {

        var oButtonClose = new sap.m.Button({ text: "Close",

            type: "Reject" } );

oButtonClose.attachBrowserEvent('click',function(){ oDialogInfo.close(); });

var oDialogInfo =

new sap.m.Dialog({ title: "Your title",

contentWidth: "400px",

contentHeight: "320px",

content: [

(new sap.m.Link({ text: "google.com - this link text",

             href: "https://google.com",

             target: "_self" })) //if new window "_blank"

           ],

     buttons: [ oButtonClose ]

});

0 Kudos

Nice)) Add CSS style and enjoy)

Private_Member_15166
Active Contributor
0 Kudos

Create a link sap.m.Link and put it in your messageBox.

santhu_gowdaz
Active Contributor
0 Kudos

SAPUI5 Explored

Custom Content add the

link:"www.scn.sap.com"

Former Member
0 Kudos

Not working - link paramter

I want the vent handler for that link also. So that once i click on the success message , i should get navigated to another page.

I need the handler function where i can write the code to navigate.

Thanks

Former Member
santhu_gowdaz
Active Contributor
0 Kudos

showCustomContent function in the above link won't help you??

Provide some code snippet what you are trying.

0 Kudos

Hi!

This code have error and not exist property href in sap.m.Link, please paste this code:

jQuery(function() {

  jQuery.sap.require('sap.m.MessageBox');

  function fnCallbackMessageBox(oAction) {

    console.log(oAction);

  }

  var link = new sap.m.Link({text : "click here",

        href:"http://google.com",               

        target: "_blank"        

  });

  sap.m.MessageBox.show(

    link, {

      icon: sap.m.MessageBox.Icon.QUESTION,

       title: "Link in message box",

       actions: [sap.m.MessageBox.Action.OK, sap.m.MessageBox.Action.CANCEL],

      onClose: fnCallbackMessageBox

     });

});

Former Member
0 Kudos

JS Bin - Collaborative JavaScript Debugging

Even there is a press event in sap.m.Link.

If used href it opens in the same tab