cancel
Showing results for 
Search instead for 
Did you mean: 

Context/Paths/Binding?

Former Member
0 Kudos

Hi All,

Here's an excerpt of code from an app I'm testing out. The code is in the createContent of the view and has had the context bound to the view. All the bindings work fine and all the values are displayed as expected.

For the ActionSheet control (oCallSheet), line 38, it seems I have find the path from the root in order to properly bind to the icl_phone_number collection. Strange because all the other bindings seem to reference the correct data, which is the contact person id passed in - e.g. - line 13 displays fine, line 15 works as well.

Workaround right now is to manually pull the path ID from the view name, which I create when navigating from master to this detail page. Any insight?

        var btnCallMenu = new sap.m.Button({
            text : "{i18n>CALL}", 
            tooltip : "{i18n>CALL}",
            icon : "sap-icon://outgoing-call",
            press: function () { 
                oCallSheet.setPlacement(sap.m.PlacementType.Vertical);
                oCallSheet.setShowCancelButton(true);
                oCallSheet.openBy(this);
            }
        });
          
        var oCallButton = new sap.m.Button({
            text: "{phone}",
            icon: {
                path: "/icl_phone_type/type",
                formatter: function (fValue) {
                    switch (fValue) {
                        case 'residence':
                            return 'sap-icon://home';
                        case 'cell':
                            return 'sap-icon://iphone';
                        default:
                            return 'sap-icon://phone';
                    }
                }
            },
            press: [oController.onCall]
        }).addStyleClass("newButton");

        // CALL ACTION SHEET
        var oCallSheet = new sap.m.ActionSheet({
            placement: sap.m.PlacementType.Bottom,
            cancelButtonPress: function () {
                jQuery.sap.log.info("oCallSheet: Cancel Button Pressed");
            }
        });

        oCallSheet.bindAggregation("buttons", "/value/" + sID + "/icl_phone_number", oCallButton);

Sorry, to add, my question is, why doesn't the following work?

  oCallSheet.bindAggregation("buttons", "icl_phone_number", oCallButton);  

Thanks!

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member182862
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi Dennis,

Thanks for creating the JSBin! I see that works well because you bind the call sheet to the model directly. My example binds to the view which contains the ActionSheet.

Do you know why I have to do the following:

oCallSheet.bindAggregation("buttons", "/value/" + sID + "/icl_phone_number", oCallButton);

and why this doesn't work?

oCallSheet.bindAggregation("buttons", "icl_phone_number", oCallButton);

former_member182862
Active Contributor
0 Kudos

Hi DJ

Sorry, I do not know how you model looks like

here is another example

JS Bin - Collaborative JavaScript Debugging

Former Member
0 Kudos

Hi Dennis,

Model looks like this:

{
      "id":7,"company":"HECO","emp_last_name":"SAFETY DIVISION","emp_first_name":"","category":"EMERGENCY","department":"SERIOUS INJURIES","call_tree":"N/A","division":"N/A","group":"N/A","position":"N/A","last_updated":"2015-07-30T17:01:18.413-10:00","icl_phone_number":[
        {
          "id":7,"phone":"(808) 123-4567","type":1,"person":7,"icl_phone_type":{
            "id":1,"type":"business"
          }
        }
      ],"icl_attachments":[
        
      ]
    },{
      "id":8,"company":"HECO","emp_last_name":"SAFETY DIVISION","emp_first_name":"","category":"EMERGENCY","department":"SERIOUS INJURIES","call_tree":"N/A","division":"N/A","group":"N/A","position":"N/A","last_updated":"2015-07-30T17:01:18.413-10:00","icl_phone_number":[
        {
          "id":8,"phone":"(808) 321-1231","type":1,"person":8,"icl_phone_type":{
            "id":1,"type":"business"
          }
        }
      ],"icl_attachments":[
        
      ]
    },{
      "id":9,"company":"HECO","emp_last_name":"DOE","emp_first_name":"JOHN","category":"PERSON","department":"ITS","call_tree":"CC-ABC-3","division":"CC","group":"ABC","position":"N/A","last_updated":"2015-07-30T17:01:18.413-10:00","icl_phone_number":[
        {
          "id":9,"phone":"(808) 134-5792","type":1,"person":9,"icl_phone_type":{
            "id":1,"type":"business"
          }
        },{
          "id":234,"phone":"(808) 213-4657","type":2,"person":9,"icl_phone_type":{
            "id":2,"type":"cell"
          }
        },{
          "id":909,"phone":"(808) 234-","type":5,"person":9,"icl_phone_type":{
            "id":5,"type":"residence"
          }
        }
      ],"icl_attachments":[
        
      ]
    }

I have a master.controller that allows a person to be selected from list and navigates to detail view based on following:

     onListSelect: function(oEvent){
         var oBindingContext = oEvent.getParameter("listItem").getBindingContext();
          var viewId = oBindingContext.sPath;
          viewId = viewId.replace(/\//g,"_");
          
          sap.ui.getCore().getEventBus().publish("nav", "to", {
               viewName: "view.contactsDetail",
               viewId: "Detail" + viewId,
               data: {
                   bindingContext: oBindingContext
               }
          });
          
     },     

Detail view sets context like so:

    onBeforeFirstShow: function (oEvent) {
        if (oEvent.data.bindingContext) {
            this.getView().setBindingContext(oEvent.data.bindingContext);
        }
    },

The detail view is set to how it was defined above in the original post. Let me know if that clears things up.

Thanks!

DJ

former_member182862
Active Contributor
0 Kudos

Hi DJ

if you have the id of the company then you have to do it like this

JS Bin - Collaborative JavaScript Debugging

Again sorry if i still get it wrong.

Thanks

-D

former_member182862
Active Contributor
0 Kudos

HI DJ

I do not advocate path being sent. Path can change. See if you can work with Id.

-D

Former Member
0 Kudos

Hi Dennis,

Please no need for apologies, your time and help is GREATLY appreciated. Unfortunately, I couldn't get the last JSBin to work, not sure how the findIndx function is supposed to work, throwing an undefined error. I think it's still a little different than what I'm trying to understand.

I'm trying to put the project in a JSBin for better clarity, but has too many files, so gotta break it down into a simpler example.

Basically trying to understand why every other control in my view has the right context and is able to bind properly, whereas the ActionSheet is not.