Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
shabl
Posts: 22
Registered: ‎11-16-2010
My Device: Any
Accepted Solution

adding menu objects to a Widget app

 

It looks like you can use addMenuItem () to add  menu items to a page, but when you navigate to a different page (e.g. by clicking on a link in the original page), the custom menu items disappear.   If you go back to the original page, the menu items reappear.

 

Is there any way to persist the menu items?  If you use a Java extension to create the application menu items, will they show on the widget browser?

 

 

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: adding menu objects to a Widget app

It is recommended that in the onload of your page that you first clear any existing menu items and then add in the ones you wish to have on that new page.

 

 

blackberry.ui.menu.clearMenuItems();

var item = new blackberry.ui.menu.MenuItem(false, 1, "Hello World", clickMe);
blackberry.ui.menu.addMenuItem(item);


  function clickMe()
  {
      alert("user just clicked me");
  }

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
shabl
Posts: 22
Registered: ‎11-16-2010
My Device: Any

Re: adding menu objects to a Widget app

Thank you for the quick response Tim.

 

That's what we do, and it works for that page, but the problem/question is when the user navigates away from that page, the menu items disappear.  So you need to add the menu items in the onload of every page.  It looks like it's designed to dynamically work for a certain page.  I just wanted to confirm if this is the expected behavior or if there's a way to keep them for the duration of the application running or until the next call to add new menu items.

 

 

Please use plain text.
Contributor
shabl
Posts: 22
Registered: ‎11-16-2010
My Device: Any

Re: adding menu objects to a Widget app

I actually found the problem out.  The new custom menu items do not disappear, but they do not work since the "clickme" callback function was loaded in the original page, not the subsequent html page.  So I need to find a way to define the callback in the new page that the user navigated to.

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: adding menu objects to a Widget app

They are not designed to live for the life of the application.  They are meant to be defined on each page loaded.

 

You can keep menu items around for the life of the application, but you need to design your application to have one main application page (index.html) and dynamically load content into that page via AJAX instead of navigating from page to page.

 

As soon as the location of the document loaded changes, the menu items will no longer work unless you clear and re-load them.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
shabl
Posts: 22
Registered: ‎11-16-2010
My Device: Any

Re: adding menu objects to a Widget app

Thanks for confirming the behavior.  So if I use the Java API to add the custom menu items to the app, will they persist during the application lifetime even when we are in the widget browser? 

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: adding menu objects to a Widget app

No they will not persist... The pointer to the JavaScript code to be executed when clicked will be lost every time you change the URL.

 

There is no way to make them persist and be functional without re-assigning the JavaScript callback to each menu item every time you load a page.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
shabl
Posts: 22
Registered: ‎11-16-2010
My Device: Any

Re: adding menu objects to a Widget app

>No they will not persist... The pointer to the JavaScript code to be executed when clicked will be lost every time you change the URL.

 

Sure, I was thinking of a Java function that will be called when clicking on a menu item.

 

 

Also, it would be very useful if there was an option to make the widget fire an application Event every time a page is loaded or unloaded in the widget webview.  Maybe you can consider this for future releases.

 

Please use plain text.
Retired
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: adding menu objects to a Widget app

For the event you are referring to.. Do you mean in Java? Or JavaScript?
Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Contributor
shabl
Posts: 22
Registered: ‎11-16-2010
My Device: Any

Re: adding menu objects to a Widget app

in Java, so for example each time the user navigates to a new page, the Java callback function can do something, maybe inject JS code in the new page to customize the menu.  You can think of other applications for this as well.

Please use plain text.