cancel
Showing results for 
Search instead for 
Did you mean: 

Press Event is not working in ObjectListItem

former_member184238
Participant
0 Kudos

Hi, 

     I have developed sample split app Application using Public Gateway Service.

https://sapes1.sapdevcenter.com/sap/opu/odata/sap/ZGWSAMPLE_SRV

In that I used ObjectLIstItem to get the list like below.

Following is the code to get the List like above.

var productList = new sap.m.GrowingList("list",{

                   threshold : 5

                    });

var objectTemplate = new sap.m.ObjectListItem({

                                                          title : "{ProductId}",

                                                          number : "{Price}",

                                                          numberUnit :"{CurrencyCode}",

                                                         press : [oController.productListTap, oController],

                                                          attributes : [new sap.m.ObjectAttribute({

                                                                    text : "{Category}"

                                                              }), new sap.m.ObjectAttribute({

                                                                   text : "{SupplierName}"

                                                           })],

                                                 firstStatus : new sap.m.ObjectStatus({

                                                                                     text : "{TypeCode}"

                                                          })

                               });

productList.bindItems("/ProductCollection", objectTemplate);

var page = new sap.m.Page("ProductPage", {

                              title : 'Product List',

                              content : [ productList ]

                    });

 

                    return page;

in ProductsController.js file

productListTap : function(evt){

                    alert("tap");

           },

But here When I click on that list item I am not getting any alert message.

Please help me to solve this.

Thanks&Regards

Sridevi

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

Do you get any JavaScript errors in the console?

I'm not sure if this would solve your problem, but how I normally invoke a function in the controller from a UI5 control is via:

press : function(oEvent) {

     oController.productListTap(oEvent);

}

former_member184238
Participant
0 Kudos

Hi Robin,

Thanks for your reply.

I am not getting any errors in Console.

The above code is not working .

When I am using normal list then press event is working.But when I am using ObjectLIstItem it's not working.

Thanks&Regards

Sridevi

Qualiture
Active Contributor
0 Kudos

Hmmm, strange... Have you tried the (deprecated) tap event to see if that works?

former_member184238
Participant
0 Kudos

I used tap event .That is also not working.

I used the below code.

var objectTemplate = new sap.m.ObjectListItem({

                                                          title : "{ProductId}",

                                                          number : "{Price}",

                                                          numberUnit :"{CurrencyCode}",

                                                         press : [oController.productListTap, oController],

                                                          attributes : [new sap.m.ObjectAttribute({

                                                                    text : "{Category}"

                                                              }), new sap.m.ObjectAttribute({

                                                                   text : "{SupplierName}"

                                                           })],

                                                 firstStatus : new sap.m.ObjectStatus({

                                                                                     text : "{TypeCode}"

                                                          })

                               });

Instead of this If I am using

var objectTemplate = new sap.m.StandardListItem({

                              title : "{Name}",

                              description : "{SupplierName}",

                              icon : "{ProductPicURL}",

                              iconInset : false,

                              iconDensityAware : false,

                              type : sap.m.ListType.Navigation,

                              tap : [ oController.productListTap, oController ]

                    });

Then it's working fine .But I am not getting above output when I am using StandardListItem.

Is there any other libraries to add when we are using ObjectListItem?

Thanks&Regards

Sridevi

Qualiture
Active Contributor
0 Kudos

Really strange... I honestly don't know why your code won't work actually.

I have created a little test HTML page, and here it perfectly works:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" charset="UTF-8" />

<title></title>

<script
src="https://sapui5.netweaver.ondemand.com/sdk/resources/sap-ui-core.js"
type="text/javascript" id="sap-ui-bootstrap" data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_bluecrystal">

</script>

<script type="text/javascript">
jQuery.sap.require("sap.m.ObjectAttribute");
jQuery.sap.require("sap.m.MessageBox");

var list = new sap.m.List("singleSelectLeftList", {
  headerText : "Items",
  mode : "SingleSelectLeft"
});

function handleOnPress(oEvent) {
  sap.m.MessageBox.show(
    "onPress Event working as expected :-)",
    sap.m.MessageBox.Icon.INFORMATION,
    "Info");
}

var oliAttr = new Array();
oliAttr.push(new sap.m.ObjectAttribute( {
  text : "Here's an attribute"
}));
oliAttr.push(new sap.m.ObjectAttribute( {
  text : "Another attribute"
}));

var olItem = new sap.m.ObjectListItem( {
  type : "Active",
  intro : "Here's an intro",
  title : "Testing sap.m.ObjectAttribute press event",
  number : "123",
  numberUnit : "Dollar",
  attributes : oliAttr,
  press : handleOnPress
});


list.addItem(olItem);

var app = new sap.m.App();
var page = new sap.m.Page( {
  title : "sap.m.ObjectListItem press test"
});
app.setInitialPage(page.getId());
page.setEnableScrolling(true);
app.addPage(page);
page.addContent(list);
app.placeAt('body');
</script>

</head>
<body id="body" class="sapUiBody">
</body>
</html>

Message was edited by: Robin van het Hof added html formatting

former_member91307
Contributor
0 Kudos

Hi Sridevi,

the difference is because of missing 'type' for object list item but present for StandardListItem.

Use type:'Active' as mentioned in robin's code above

Thanks and Regards,

former_member184238
Participant
0 Kudos

Hi,

It's working fine.

Thank you very much for your valuable reply.

Regards

Sridevi

Answers (0)