question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically setting the press event for a sap.m.Button inside a sap.m.Table

See original GitHub issue

Hi, I’d like to know what is the simplest correct way (if one exists) to dynamically bind the press event on a sap.m.Button contained into a sap.m.Table?

I was (somehow) expecting this code to work:

 new sap.m.Button({
        text:"{w/buttonText}",
        type:"{w/buttonType}",
        enabled:"{w/buttonEnabled}",
        press:"{w/buttonCallback}"
       }),

with the w/ being a JSON object of this type:

interface WorkflowInInvoiceTable {
  buttonText: string
  buttonType: sap.m.ButtonType
  buttonEnabled: boolean
  buttonCallback: (e) => void
}

But it seems this is not the case:

Uncaught TypeError: I.fFunction.call is not a function
    at f.a.fireEvent (sap-ui-core.js:449)
    at f.a.fireEvent (sap-ui-core.js:989)
    at f.firePress (sap-ui-core.js:573)
    at f.B.ontap (library-preload.js:696)
    at f.a._handleEvent (sap-ui-core.js:974)
    at constructor.U._handleEvent (sap-ui-core.js:1203)
    at HTMLBodyElement.p (sap-ui-core.js:115)
    at HTMLBodyElement.dispatch (sap-ui-core.js:126)
    at g (sap-ui-core.js:1783)
    at HTMLBodyElement.p (sap-ui-core.js:1783)



Everything binds perfectly but the {w/buttonCallback} that, if put into a normal text field, is correctly stringified.

Note: I’ve already worked out the gazillionth workaround, so I don’t need a consultant action, but having data and manipulators serializable into the same JSON object could be more elegant.

–R

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
codeworriorcommented, Sep 21, 2017

Data binding is only supported for properties and aggregations, not for events, not for associations. In declarative views (XMLViews - sorry to mention them in your post @RobertoMalatesta 😃 ), you can refer to controller methods by their name. In JS code, you can to refer to them by reference:

w = /* some instance of WorkflowInInvoiceTable */  ...;
new sap.m.Button({
        text:"{w/buttonText}",
        type:"{w/buttonType}",
        enabled:"{w/buttonEnabled}",
        press: [w.buttonCallback, w]
}),

The array notation with function + context (thisArg) is UI5 specific and ensures that the handler is called with the right this. For sure you can use w.buttonCallback.bind(w) instead.

HTH + Kind Regards

0reactions
RobertoMalatestacommented, Sep 25, 2017

@eomere I suspect it won’t work inside a sap.m.Table (the problem I had), since sap.m.ColumnListItem templates the column once per column. (So the press function is the same for all elements in the column, not dynamically set with different functions called on different items). I could be wrong since it was one year ago. @codeworrior can correct me.

–R

Read more comments on GitHub >

github_iconTop Results From Across the Web

Action handling of dynamically created button inside a table
I get a java.lang.NullPointerException at runtime when I press the button. One more thing I didnt bind any property of the button with...
Read more >
Dynamic binding of items in sap.m.Table using JS views
I am developing a master detail page for a Purchase Order application. In master page, i display the list of Purchase Orders &...
Read more >
Dynamic binding of items in sap.m.Table using XML views
Up till here everything is fine but I've been struggling with my latest requirement which is: show the skills of the selected employee...
Read more >
how make the button and text visible and invisible dynamically ...
My requirement: i have used sap.m.table and column fields are ... button and text visible and invisible dynamically in sap.m.table column?
Read more >
dynamic button press event always triggering last button events
Hi I have created buttons dynamically with unique ID and each ... Here is my code for(i=0; i<=4; i++) { var oBtnSave =...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found